-
Dynamic instance/Variable names in loops
This has been bugging me for a while but I'll have a series of movieclips, variables, input boxes, or whatever with a name then a number as their names. For example input0, input1, input2, etc. In AS2 I could throw them into a loop like so:
Code:
for(i = 0; i<3; i++)
{
this["input"+i].text = array[i];
}
...or something to that regard. How do I do this in AS3 where I can set up a loop and dynamically call the numbered instance name?
-
Senior Member
It's not really much different.
"this" in AS3, in the document class or in a frame script, refers to the timeline; so safer to refer to the stage if these things are already placed on stage.
You're probably having a problem with what "this" you're talking about. Try using root["input"+i] or root.stage.getChildByName("input"+i) if you're looking for fields placed directly on the stage before compiling.
-
Put your textfields into their own array...that way you store a reference to the object instead of a name that you have to lookup later.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|