Tom
Tom

Reputation: 1095

How do I loop through children but only as MovieClip?

I have a MC with movieclips and shapes. Is there a way to loop throuh each child but only for MovieClips? I keep getting a null object because of the shape.

for (var i:int = 0; i < this.numChildren; i++) {
     var obj:MovieClip = getChildAt(i) as MovieClip;
}

Here I thought "as MovieClip" would only trace out MovieClips...

Upvotes: 2

Views: 402

Answers (1)

sanchez
sanchez

Reputation: 4530

for (var i:int = 0; i < this.numChildren; i++) {
    if( getChildAt(i) is MovieClip ){
        var obj:MovieClip = getChildAt(i) as MovieClip;
        ...
    }
}

Upvotes: 3

Related Questions