I want to dynamically access a bunch of objects in my mxml. I can construct their name/id. In Javascript I can do getElementById(ID)
to get the object. How can I do this in Actionscript?
I really can't do getChildByName
because it is too cumbersome: I have access to object A, which has a child B, which has a child C, which have the children D, E & F (their names are related to A's name). I want to get D, E & F. For getChildByName
, it seems I have to use A to get B, then get C, and then get D, E & F. And if add a new parent to B (change the mxml hierarchy), then the code will break… And I really don't want to do that.
Any advice?
Thx!
Update: What I am asking is, how do I access object D given its name and/or id, both of which are strings.
Best Answer
Since the children are actually like "properties" of the document, you should be able to do something like this:
var elem:Type_of_E = this["constructed_id_of_E"];
If you are in a subdocument of the document just use parentDocument["constructed_id_of_E"] to get the element.