eval(string)
Top  Previous  Next


SWiSH Player Support
SWF5 or later - Supported Internally

Syntax
eval(expression);

Arguments
expression: A string containing the name of a variable.

Returns
Nothing.

Description
Function: Accesses variables, properties, Objects or Movie Clips 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 Sprite, a reference to the Object or Sprite is returned.

If the element named in the expression cannot be found, undefined is returned.

You can also use the eval function to dynamically set and retrieve the value of a variable or Instance name.

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

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

Item5 = "test";
x = 5

y = eval("Item" add x);
trace(y);
// Output: test


Flash MX Differences
Flash MX can use eval to return references to Objects, properties and Movie Clips as well. SWiSHscript eval() can only return references to variables.