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<mcContainer.numChildren-1; i++) { 
var mc:MovieClip = MovieClip(mcContainer.getChildAt(i)); 
mc.doStuff(); 
}

ActionScript 2 Code Sample:

for (var Item in Parent) {
	if (typeof (Parent[Item]) == "movieclip") {
		Parent[Item].doSomething();
	}
}

You may also like...

3 Responses

  1. Alex says:

    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.

  2. Mike says:

    Nice blog. I was looking for this solution a while back.

Leave a Reply