03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

eval function<br />

eval(expression:Object) : Object<br />

eval(expression:String) : Object<br />

Accesses variables, properties, objects, or movie clips by name. If expression is a variable or a<br />

property, the value of the variable or property is returned. If expression is an object or movie<br />

clip, a reference to the object or movie clip is returned. If the element named in expression<br />

cannot be found, undefined is returned.<br />

In Flash 4, eval() was used to simulate arrays; in Flash 5 or later, you should use the Array<br />

class to simulate arrays.<br />

In Flash 4, you can also use eval() to dynamically set <strong>and</strong> retrieve the value of a variable or<br />

instance name. However, you can also do this with the array access operator ([]).<br />

In Flash 5 or later, you cannot use eval() to dynamically set <strong>and</strong> retrieve the value of a<br />

variable or instance name, because you cannot useeval() on the left side of an equation. For<br />

example, replace the code<br />

eval ("var" + i) = "first";<br />

with this:<br />

this["var"+i] = "first"<br />

or this:<br />

set ("var" + i, "first");<br />

Availability: <strong>ActionScript</strong> 1.0; Flash Player 5 - Flash Player 5 or later for full functionality.<br />

You can use the eval() function when exporting to Flash Player 4, but you must use slash<br />

notation <strong>and</strong> can access only variables, not properties or objects.<br />

Parameters<br />

expression:Object - The name of a variable, property, object, or movie clip to retrieve. This<br />

parameter can be either a String or a direct reference to the object instance (i.e use of<br />

quotation marks (" ") is optional.)<br />

Returns<br />

Object - A value, reference to an object or movie clip, or undefined .<br />

Example<br />

The following example uses eval() to set properties for dynamically named movie clips. This<br />

<strong>ActionScript</strong> sets the _rotation property for three movie clips, called square1_mc,<br />

square2_mc, <strong>and</strong> square3_mc.<br />

Global Functions 57

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!