|I l @ ve RuBoard|
All sophisticated programming languages use variables to store information. You may store information for a number of reasons. A variable has two parts : its name and a value.
You will need to store information to write complex computer programs. Sometimes you will only store the information for a short period of time. For instance, you may want your program to repeat a set of commands 10 times. In that case, you will need to count the number of times the commands have been repeated and continue on after this counter reaches 10.
In other cases, you will want to store information for longer periods of time. For instance, you can ask the user to enter her name and then you can store this information in a variable. Later in the Flash movie, you can display this name.
The name of a variable is usually a word or group of words. Sometimes it is a single letter. In general, you should make the name of the variable as descriptive as possible.
For instance, if you want to store the name of the user in a variable, userName is a good choice for the variable name. A bad choice would be n , which is too short, or name , which could be confused with the name of something else in the Flash movie.
Spaces cannot be used in variable names, and neither can special characters . But numbers can be used. So a variable name may be player2 .
You can store many different types of information in variables. Numbers are the simplest. You can store the number 7 in a variable, for instance.
When writing about strings, quotes are used to define that the value is a string and not another type of variable. For instance, 7 is the number 7, whereas "7" is a string with a single character, the digit 7.
In other programming languages, you would normally have to decide in advance what type of information each variable would hold and write that at the beginning of your program. For instance, you would declare that there is a variable named userName and that it holds a string. However, in ActionScript, you don't have to declare variables in advance. You just use them, and Flash creates the variables on-the-fly the first time they are used.
In addition, the variables are not restricted to holding only one type of information. The variable userName could hold a string at one point and a number at another point.
This flexibility is rarely needed, but it is one less thing for ActionScript programmers to worry about.
There are other types of variables besides numbers and strings. For instance, arrays can hold lists of information instead of a single piece of information. We'll look at arrays and other data types later in the book as they are needed.
|I l @ ve RuBoard|