Skip to main content
January 12, 2007
Question

how to loop through movieclip children

  • January 12, 2007
  • 4 replies
  • 873 views
I have a bunch of named instances of textfields attached to a movieclip instance. Using actionscript, I want to loop through those textfield instances. I need to alter properties of each one, and it'd help if I could get a reference to each of them in turn in subsequent iteration of a loop, instead of having separate code that refers to each by its instance name. Is there a way?
This topic has been closed for replies.

4 replies

January 12, 2007
Nevermind about the other question, I've figured out a couple ways to do it.
January 12, 2007
Thanks again. I have another question. My textfields (12) are named myText0, myText1, myText2, etc. I want to set the elements of an array such that myArray[0] = myText0, myArray[1] = myText1, etc. I could write all those assignment statements, one for each textfield. I wanted to write

for(var index = 0; i < 12; i++) {
myArray[index] = my_mc.myTextindex;
}

but I can't because i is a number, and I don't know how to append numbers to instance names. (Is it possible?)

The for..in statement

var index = 11;
for (var t in my_mc) {
myArray[index] = t;
index--;
}

seems to work. But if I add more children to my_mc, it won't. I could only put the first 12 children in myArray, but I'm not sure how for..in orders the children it enumerates. Apparently they're in the correct order now, but will that remain true if I add children to my_mc?

I may end up having to write 12 assignments like

myArray[0] = my_mc.myText0;

to make sure the right children are in myArray, but I'd rather not. Do you see what I mean?
Inspiring
January 12, 2007
Hi if you would like to get all the Text Fields In a Flash File u can use a recursive Function to get all the Text fields
Eventhough it is inside some other movie Clip

See the Below code
January 12, 2007
Thanks.
January 12, 2007
Thanks. I thought I tried that and it didn't work, but I must have made a mistake, because it works now.
Marghoob Sulemaan
Inspiring
January 12, 2007
you may use for...in method to do so....

for(var i in your_mc) {
....
}