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: , , , , , , , , , , ,

3 Responses to “Loop through child movie clips in AS3 and AS2”

  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. am3media » Blog Archive » Flash AS3 Get Child By Name Says:

    [...] You can also do this by using getAtIndex. See here: http://am3media.com/site/flash/loop-through-child-movie-clips-in-as3-and-as2 [...]

  3. Mike Says:

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

Leave a Reply