Reputation: 497
Is it possible to fill an array with the Movieclips already on the stage (or within another movieclip)?
E.g. if '_level' is a Movieclip with more movieclips inside it, I want to do something like this:
var currentClip:MovieClip;
for (var i:int = 0; i < _level.numChildren; i++) {
currentClip = _level[i];
.....
}
Upvotes: 0
Views: 1646
Reputation: 5497
you can iterate through them with a for loop:
var array:Array=new Array();
for(var i:int=0; i < stage.numchildren ; i++) {
array.push(stage.getChildAt(i));
}
you can do a recursive function for this to get the children of the children, etc, like:
public var array:Array=new Array();
public function getChildren(do:DisplayObject){
var arr:Array=new Array();
for(var i:int=0; i < do.numchildren ; i++) {
getChildren(getChildAt(i));
}
array.push(do);
}
and call it somewhere like:
getChildren(stage);
Upvotes: 3