Emulating arrays
11
Using variables
To specify a variable on a timeline, use slash syntax (/) combined with dots (..) and colons (:).
You can also use the dot notation.
The following code refers to the
car
variable on the main timeline:
/:car
_root.car
The following example shows the
car
variable in a movie clip instance that resides on the
main timeline:
/mc1/mc2/:car
_root.mc1.mc2.car
The following example shows the
car
variable in a movie clip instance that resides on the
current timeline:
mc2/:car
mc2.car
Emulating arrays
Arrays are useful for creating and manipulating ordered lists of information such as variables
and values. However, Flash Lite 1.1 does not support native array data structures. A common
technique in Flash Lite (and Flash 4) programming is to emulate arrays with string processing.
An emulated array is also called a pseudo-array. The key to pseudo-array processing is the
eval()
ActionScript function, which lets you access variables, properties, or movie clips by
name. For more information, see
“Using the eval() function” on page 17
.
A pseudo-array typically consists of two or more variables that share the same base name,
followed by a numeric suffix. The suffix is the index for each array element
.
For example, suppose you create the following ActionScript variables:
color_1 = "orange";
color_2 = "green";
color_3 = "blue";
color_4 = "red";
You can then use the following code to loop over the elements in the pseudo-array:
for (i = 1; i <=4; i++) {
trace (eval ("color_" add i));
}
Содержание FLASH 8-LEARNING FLASH LITE 1.X ACTIONSCRIPT
Страница 1: ...Learning Flash Lite 1 X ActionScript ...
Страница 4: ...4 Contents ...
Страница 8: ...8 About Flash Lite 1 x ActionScript ...
Страница 18: ...18 Flash 4 ActionScript Primer ...