About variables
87
It’s a good idea to assign a value to a variable the first time you declare the variable. Assigning
an initial value is called
initializing
the variable, and it’s often done on Frame 1 of the
Timeline or from within a class that loads when the SWF file begins to play. There are
different kinds of variables, which are affected by scope. For more information on different
kinds of variables and scope, see
“About variables and scope” on page 96
.
Variables can hold different types of data; for more information, see
“About data types”
on page 72
. The type of data that a variable contains affects how the variable’s value changes
when you assign that value in a script.
Typical types of information that you can store in a variable include a URL (String type), a
user’s name (String type), the result of a mathematical operation (Number type), the number
of times an event occurred (Number type), or whether a user has clicked a particular button
(Boolean type). Each SWF file and object instance (such as a movie clip) 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 Output
panel. Then, the value displays in the Output panel when you test the SWF file in the test
environment. For example,
trace(hoursWorked)
sends the value of the variable
hoursWorked
to the Output panel in the test environment. You can also check and set the
variable values in the Debugger in the test environment.
For more information on variables, see the following topics:
■
“About declaring variables” on page 88
■
“About assigning values” on page 88
■
“About naming variables” on page 91
■
“Using variables in an application” on page 92
■
“About variables and scope” on page 96
■
“About default values” on page 88
■
“About operators and variables” on page 90
■
“About loading variables” on page 100
■
“Using variables in a project” on page 106
TIP
Initializing a variable helps you track and compare the variable’s value as the SWF file
plays.
NO
T
E
Flash Player 7 and later evaluate uninitialized variables differently than Flash Player 6
and earlier. If you have written scripts for Flash Player 6 and plan to write or port scripts
for Flash Player 7 or later, you should be understand these differences to avoid
unexpected behavior.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...