Using the eval() function
17
Using the eval() function
The
eval()
function lets you dynamically reference variables and movie clip instances at
runtime. The
eval()
function takes a string expression as a parameter and returns either the
value of the variable represented by that expression or a reference to a movie clip.
For example, the following code evaluates the value of the
name
ActionScript variable and
assigns the result to
nameValue
:
name = "Jack";
nameValue = eval("name");
// result: nameValue = "Jack"
The
eval()
function is often used with
for()
loops and the
add
(string concatenation)
operator to create string-based arrays, because Flash Lite doesn’t support native array data
structures. For more information, see
“Emulating arrays” on page 11
.
You can also use
eval()
to reference movie clip instances by name. For example, suppose you
had three movie clips named
clip1
,
clip2
, and
clip3
. The following
for()
loop increments
the
x
position of each clip by 10 pixels:
for(index = 1; index <= 3; index++) {
eval("clip" add index)._x += 10
}
Содержание 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 ...