Sometimes you want a list of everything inside a movieclip. For example: you want to know the instance names of every movie in the root.
ActionScript 2
A little trick that I used a lot in AS2 is:
for(var i in _root){
trace('key: ' + i + ', value: ' + _root[i]);
}
or
for(var i in target_mc){
trace('key: ' + i + ', value: ' + target_mc[i]);
}
to find out which movies are in target_mc
It was not only a trick to trace everything, I also used it to reset movieclips (place them outside the stage, or delete them) or quickly make buttons out of them:
for(var i in target_mc){
target_mc[i].id = i;
target_mc[i].onRelease = function (){
trace ("id = " + this.id); // onRelease the id will be called (the name of the movie)
};
}
ActionScript 3
But in AS3 this doesn’t work any more!
And I know: AS3 should make my life easier…. well if I see the solution to the problem created by AS3, I have to disagree!
for (var i:uint = 0; i < target_mc.numChildren; i++){
trace ('\t|\t ' +i+'.\t name:' + target_mc.getChildAt(i).name + '\t type:' + typeof (target_mc.getChildAt(i))+ '\t' + target_mc.getChildAt(i));
}
In AS3 you first have to get the "number of children" (numChildren) in a DisplayObjectContainer, then you have to say which child you want (getChildAt(i))...
A good thing about AS3 is, you get everything in a movieClip, even shapes you made there without a instance name.
I'm glad that I work with FlashDevelop, which has snippets so I don't have to type this constantly!
(For the people that use FlashDevelop too, here is my snippet:)
// $(Clipboard)is a DisplayObject
trace ('+ number of DisplayObject: ' + $(Clipboard).numChildren + ' --------------------------------');
for (var i:uint = 0; i < $(Clipboard).numChildren; i++){
trace ('\t|\t ' +i+'.\t name:' + $(Clipboard).getChildAt(i).name + '\t type:' + typeof ($(Clipboard).getChildAt(i))+ '\t' + $(Clipboard).getChildAt(i));
}
trace ('\t+ --------------------------------------------------------------------------------------');








![Grim Grinning Grunt a [mck] custom](http://www.matthijskamstra.nl/blog/wp-content/uploads/grim_grinning_grunt_v01a.jpg)
