html5-img
1 / 14

Primitive Data Types

Primitive Data Types. Boolean Data Type: It is used in logical operations to represent a certain state. It could only hold two values: true false Ex) var f2:Boolean = true;. Primitive Data Types. String Data Type: It used to store data as a text ( a sequence of characters).

dora
Télécharger la présentation

Primitive Data Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Primitive Data Types • Boolean Data Type: • It is used in logical operations to represent a certain state. • It could only hold two values: • true • false • Ex) var f2:Boolean = true;

  2. Primitive Data Types • String Data Type: • It used to store data as a text ( a sequence of characters). • Ex) “This is some text” • String in flash should be enclosed within double quotation (“”) • Ex) to declare a variable (s) of type String and store “some text” in it: var s:String = “some text”;

  3. Primitive Data Types • Each character in a string has an index. • The indices of characters are numbered (0,1,2,3,…) from left to right. • The string characters created in the previous example have indices as follows: s o m e t e x t 0 1 2 3 4 5 6 7 8

  4. Primitive Data Types • Functions to manipulate string: • charAt(i); • This function returns a character from a string found in index (i) • i: integer number represent an index. • Ex) var s:String = “some text”; trace(s.charAt(2)); // m • indexOf(str); • This function returns the index of the passed (str) within the text. • Ex) trace(s.indexOf(“m”)); // 2

  5. Primitive Data Types • length; • Returns the number of characters in the string. • Ex) trace(s.length); // 9 • substr(index,length); • Returns a part of the string as specified in the parameters. • index: an integer gives the starting point of the taken part. • length: the number of characters to take starting at (index). • Ex) trace(s.substr(1,5));// ome t s o m e t e x t 0 1 2 3 4 5 6 7 8 index

  6. Primitive Data Types • toUpperCase(); • Returns the capital letter representation of the string. • toLowerCase(); • Returns the lower letter representation of the string.

  7. String Example • Ex) this example illustrate how to build a flash program to read string value from keyboard, convert it to its capital representation, and print the result in a text field on the stage: • Create a flash file. • Insert a text field on the stage, convert its type to (Input Text) and give it an instance name (txtinput) • When you change the type of a text field to (Input Text), you can insert text values into it at runtime from keyboard. • Giving an instance name to a text fields allow us to access it using action script.

  8. String Example • Insert a text field on the stage. Convert its type to dynamic and give it an instance name (txtoutput) • Add a button on the stage. Insert the text (Convert to Capital) in the button. • In the action pane of the button, add the following script: on(press) { var s:String; s = txtinput.text; txtoutput.text = s.toUpperCase(); } To take the text inserted into (txtinput) and assign it to (s) To return the capital letter representation of s. Then assign it to (txtoutput)

  9. Global variable • Global variables are visible to every timeline and every scene in your flash file. • To declare (or create) a variable with global scope, use the _global identifier before the variable name and do not use the var keyword. • Ex) _global.myName = “globalvar";

  10. Flash Sounds • There are two ways to add sounds to our flash file: • import a sound file (in whatever format the flash editor can handle, e.g. mp3, wav... etc), and pull it onto the stage. • Ex) • create new flash file • Go to FileImportImport to Library • Choose the sound file from your computer, and click open. • You can notice that your sound file was added to your library. • Now, Drag and drop that flash symbol into the stage. • Test the movie

  11. Flash Sounds • if you want to have better control in playing the sound file, you may need some actionscripts. • starting and stopping the music by pressing the corresponding button. • Ex) This example illustrates how to control sounds inside flash program. • Open a new file in the Flash • Import a sound file into the library. • MRC on the imported sound(in the library window; you may need to open the library window first), and select linkage on the pop up menu.

  12. Flash Sounds • check the export to actionscript option and type the name "mysound" in the textbox. • This will assign an id to the imported sound, so later on the actionscripts can refer to it. • Ok, back to the main stage. Select the first frame on the timeline, open the action window and put the following code in it: var snd:Sound = new Sound();snd.attachSound("mysound"); • Basically, the above code will create a sound object and attach the imported sound file to it. • insert a (play) button in the stage and write the following code in the action pane of it:

  13. Flash Sounds • on(release) • {_root.snd.start(0, 10); • } Action is performed when releasing the button _root: to access every object in the main timeline Start(0,10): This will start playing the sound (and loops 10 times) when the button is clicked.

  14. Flash Sounds • Repeat step 6 to create the stop button but associated with the following actionscritps instead: on(release){_root.snd.stop(); } Stop(): to stop the sound

More Related