Accessibility

TechNote (Archived)

Eval() on the left side of an argument causes error

Issue


An error is generated when attempting to dynamically assign the left and the right side of an argument in Macromedia Flash MX using eval() as follows:
eval("TextField" +i) = array[i];

This same code, which worked correctly in Macromedia Flash 5, displays the following error in the output window:

Left side of assignment operator must be variable or property

Reason


Although this code was allowed in Macromedia Flash 5, it actually deviates from the ECMA-262 standard. Macromedia Flash MX is now fully ECMA-262 complaint and no longer allows this structure when authoring a Macromedia Flash Player 6 SWF.

Solution


When publishing as Macromedia Flash Player 6 SWF, replace theeval() in the code above with the keywordthis as follows:
this["TextField"+i] = array[i];

When using Macromedia Flash MX to publish a Macromedia Flash Player 5 SWF then eval() on the left side is allowed in the ActionScript editor. The Macromedia Flash Player 6 will still play Flash 5 SWF files correctly if they were created using this code structure.

Note: There is one code structure which will not work correctly in Macromedia Flash Player 6. If a left-side eval() is created for publishing as a Macromedia Flash Player 5 SWF where that eval combines two strings the returned value will be undefined. For example:
eval("TextField" + "One") = "string1"
trace("TextFieldOne")

Will return "undefined" in Test Movie and the eval() will fail in Macromedia Flash Player 6.

To correct the problem, enclose the string concatenation in an extra set of parentheses:
eval(("TextField" + "One")) = "string1"

or convert the structure to use this[]:
this["TextField" + "One"] = "string1"

This structure will work correctly in Macromedia Flash Player 6.

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:tn_16187
Browser:Chrome
Internet Explorer
Netscape
Opera
Safari
Firefox
Database:DB2
Informix
MySQL
Oracle
SQL Server
Sybase
MS Access

Products Affected: