« Home « Kết quả tìm kiếm

Creating Variables


Tóm tắt Xem thử

- When you create variables, you must give them names—monikers you cannot change, though you can alter their contents.
- var myFullName:String = "Jobe Makar";.
- The script declares a new variable, associates a data type with that variable, and gives the variable data to store..
- After the variable name (the string of letters after var) you add a colon.
- The Actions panel gives you a drop-down list of data types you can add after the colon, or you can type the data type yourself.
- sets what is found to its right as the value of the variable.
- Above, "Jobe Makar".
- is the value of myFullName..
- You can also declare a variable without giving it a value.
- The script tells the Flash Player that when the variable myFullName is used at some point.
- myFullName = "Jobe Makar";.
- It is now recommended to use the var syntax so that you can make full use of data typing and for good memory management..
- You can name a variable anything, as long as you follow some simple rules.
- Name your variables according to the data they contain—for example, numberOfDays, favoriteDogsName, totalTax, and so on—so you can remember and use them easily throughout your project..
- Once you create a variable and assign it a value, you can use that value in any script simply by referencing its name.
- This code creates a variable named myFavoriteNumber and assigns it a value of 66.
- If the value of your variable changes, the scripts that use it will execute differently because some of the actions are based on the current value of that variable..
- For example, var myFullName:String = "Jobe Makar".
- "Jobe Makar".
- assigns a text value of .
- to myFavoriteNumber, not a number value of 27..
- If the music were currently on (true), the idea would be to turn the music.
- off and then switch the value of the variable to false.
- If the music were off (false), the music would need to be turned on and the value of the variable set to true.
- Because the value of musicPlaying is switched between true and false with each successive button click, the script on the button would evaluate its current value and turn the music on or off..
- You can use numeric values for people's ages, for scores in a game, and to track the number of times someone has clicked a button—to name just a few uses..
- or something else—to variables, you can use an expression to set the value.
- The third line in this script uses an expression to set the value of bottlesLeft.
- expression substitutes the values of the variables (99 and 1) and performs a subtraction..
- The end result is that the variable bottlesLeft is assigned a value of 98.
- It's important to note that the structure of the expression determines whether it will result in a string, Boolean, or number value..
- var someone:String = "Jobe Makar";.
- A variable called someone is created in the first line of the script.
- In the second line, the value of the coffeeBoy variable is set to the string "Jobe Makar".
- by referencing the value of someone.
- If the value of someone changes later, coffeeBoy will not reflect the change..
- The next script creates a variable named myVariable and places it on the root (main) timeline:.
- You can properly declare a variable on a timeline only from the timeline itself (a script attached to a frame or button in the timeline).
- This does not mean that you can't change the value of a variable properly from another timeline, but it's recommended that you first declare the variable in that timeline.
- In myClip2_mc, you can then change the value of the variable that is living in myClip1_mc with the following code:.
- By coding in this manner, you can still make use of the strict typing of variables in Flash while allowing variables to be modified from another timeline..
- You can also create variables directly on objects.
- person.name = "Jobe";.
- Because dynamic text fields can be used to display the value contained in a particular piece of data, in this exercise you set and use variables that ultimately control what's displayed on the screen for a news site project..
- Select Frame 1 of the Actions layer on the main timeline.
- To structure the data for this application, you'll use objects—each of which will be named for a different day of the week and will store all the news for that day accordingly.
- Note that we only discuss the ActionScript for Monday and Tuesday because the ActionScript for the rest of the week works in the same way..
- Entering the preceding script on Frame 1 of the timeline creates the objects monday and tuesday

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt