header image
 

eval() is gone is Actionscript 3

I was trying to refer to a movieclip object whose name is computed from a variable. In AS2, I would be using something like eval(variableName).property to read/write to the property of the movieclip. I found that it no longer work in AS3 as eval() has been removed. After some research through the AS3 reference, I found out there is a new method call getChildByName()  under the DisplayObjectContainer class. It goes something like this:

 getChildByName(variableName).x = 100;

The above would set the property of a movieclip with the name stored by the variable variableName.

So when one door is closed, another door would open. :)

~ by brianchau on December 23, 2007.

One Response to “eval() is gone is Actionscript 3”

  1. I never needed eval(). In AS3 someparent[variableString].x still works. Do more, type less :)

Leave a Reply