De-I > eval

eval

Syntax

eval(expression);

Arguments

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

Description

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

In Flash 4, the eval function was used to simulate an arrays. In Flash 5 it is recommended that you use the Array object to create arrays.

Note: The ActionScript eval action is not the same as the JavaScript eval function, and cannot be used to evaluate statements.

Player

Flash 5 or later for full functionality. You can use eval when exporting to the Flash 4 Player, but you must use slash notation, and can only access variables, not properties or objects.

Example

The following example uses eval to determine the value of the variable x, and sets it to the value of y:

x = 3; 
y = eval("x");

The following example uses eval to reference the movie clip object associated with a movie clip instance on the Stage, Ball:

eval("_root.Ball");

See also

Array (object)