Ok lets say you have 10 identical items, placed on the stage using the Flash IDE and values in each "pre-populated" and you want to do something to all instances - say read off the values - obviously you use a loop and do this - so this is supposedly bad (eval) method....
items=10;
for (item=1;item
theObject=eval("_root.field"+item);
trace("item "+theObject._name+" has a value of "+theObject.text);
}
In bracket notation it would be:
items=10;
for (item=1;item
theText=_root["field"+item].text;
trace("item "+theObject._name+" has a value of "+theObject.text);
}
it works, but is it only me who finds the fact that there is no dot after the root command a bit odd?
common sense would make you thing it should be
theText=_root.["field"+item].text;
but no - another Actionscript oddity! I remember struggling with this years ago when I had problems using an eval statement inside a dynamic element - thankfully examples on the web rescued me at the time - so today after revisiting the technique again - I thought it was worth pointing out!
No comments:
Post a Comment