Loop through child movie clips in AS3 and AS2
To iterate through all children in a display object container…
ActionScript 3 Code Sample:
for(var i=0; i
ActionScript 2 Code Sample:
for (var Item in Parent) {
if (typeof (Parent[Item]) == "movieclip") {
Parent[Item].doSomething();
}
}
admin
Tags: as2, as3, child, display, Flash, getChildAt, iterate, loop, movieclips, new, objects, old

March 18th, 2009 at 1:31 pm
Try this:
var count:uint = mySprite.numChildren;
for(var i:uint=0;i<count;i++){
mySprite.removeChildAt(0);
}
Use the 0 (zero) index for removeChildAt as everytime you remove an item, it shifts everything in the display list down by 1.
May 6th, 2009 at 9:28 am
[...] You can also do this by using getAtIndex. See here: http://am3media.com/site/flash/loop-through-child-movie-clips-in-as3-and-as2 [...]
October 9th, 2009 at 9:57 am
Nice blog. I was looking for this solution a while back.