About variables
27
The following example shows how you can use these operators and the difference between them:
//Create a new instance of LoadVars class
var myLV:LoadVars = new LoadVars();
//instanceof operator specifies instance of what class
if (myLV instanceof LoadVars) {
trace("yes, it's a loadvars instance");
}
//typeof operator does not specify class, only specifies that myLV is an object
var typeResult:String = typeof(myLV);
trace(typeResult);
About variables
A
variable
is a container that holds information. The container itself is always the same, but the
contents can change. By changing the value of a variable as the SWF file plays, you can record and
save information about what the user has done, record values that change as the SWF file plays, or
evaluate whether a condition is true or false.
It’s a good idea always to assign a variable a known value the first time you define the variable.
This is known as
initializing a variable
. If a variable is declared in the FLA (instead of in an
external file), it works only for the frame where the variable is declared. Only the frame code for
that frame is scanned, so the second frame would not recognize the variable if it was referenced.
Initializing a variable helps you track and compare the variable’s value as the SWF file plays.
Variables can hold any type of data (see
“About data types” on page 18
). The type of data a
variable contains affects how the variable’s value changes when it is assigned in a script.
Typical types of information that you can store in a variable include a URL, a user’s name, the
result of a mathematical operation, the number of times an event occurred, or whether a button
has been clicked. Each SWF file and movie clip instance has a set of variables, with each variable
having a value independent of variables in other SWF files or movie clips.
To view the value of a variable, use the
trace()
statement to send the value to the log file. For
example,
trace(hoursWorked)
sends the value of the variable
hoursWorked
to the log file. You
can then review the log file to see if your variables are being set or changed as expected.
For more information, see the following topics:
•
“Naming a variable” on page 27
•
“Scoping and declaring variables” on page 28
•
“Using variables in a program” on page 29
Naming a variable
A variable’s name must follow these rules:
•
It must be an identifier (see
“Terminology” on page 11
).
•
It cannot be a keyword or an ActionScript literal such as
true
,
false
,
null
, or
undefined
.
•
It must be unique within its scope (see
“Scoping and declaring variables” on page 28
).
Содержание FLEX
Страница 1: ...Flex ActionScript Language Reference ...
Страница 8: ......
Страница 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0 ...
Страница 76: ......
Страница 133: ...break 133 See also for for in do while while switch case continue throw try catch finally ...
Страница 135: ...case 135 See also break default strict equality switch ...
Страница 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while ...
Страница 229: ...while 229 i 3 The following result is written to the log file 0 3 6 9 12 15 18 See also do while continue for for in ...
Страница 808: ...808 Chapter 7 ActionScript for Flash ...
Страница 810: ...810 Appendix A Deprecated Flash 4 operators ...
Страница 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code ...
Страница 816: ...816 Appendix B Keyboard Keys and Key Code Values ...
Страница 822: ...822 Index ...