eval ()

Availability

Flash Lite 1.0.

Usage

eval(expression)

Operands

expression A string containing the name of a variable, property, object, or movie clip to retrieve.

Description

Function; accesses variables, properties, objects, or movie clips by name. If expression is a variable or a property, the value of the variable or property is returned. If expression is an object or movie clip, a reference to the object or movie clip is returned. If the element named in expression cannot be found, undefined is returned.

You can use eval() to simulate arrays, or to dynamically set and retrieve the value of a variable.

Example

The following example uses eval() to determine the value of the expression "piece" + x. Because the result is a variable name, piece3, eval() returns the value of the variable and assigns it to y:

piece3 = "dangerous";
x = 3; 
y = eval("piece" add x);
trace(y);        // Output: dangerous.

The following example demonstrates how an array could be simulated:

name1 = "mike";
name2 = "debbie";
name3 = "logan";
for(i = 1; i <= 3; i++) {
    trace (eval("name" add i));        // Output: mike, debbie, logan
}