Macromedia flash 8-learning flash lite 1.x actionscript User Manual

Page of 26
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 
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
}