View Full Version : for( var i in this).... or not
walnutfish
07-19-2006, 04:19 PM
I've been trying to understand how this breaks down. In AS 2 _root is a movieclip, but in AS 3 it's a timeline. How can I enumerate through the objects in the timeline? With AS 2 I used the "for (var i in this)", but that doesn't work in our 'new-fangled' scripting language.
walnutfish
07-19-2006, 07:24 PM
This is a useful function for tree breakdowns... not excactly what I'm looking for.
function traceDisplayList(container:DisplayObjectContainer,
indentString:String = ""):void {
var child:DisplayObject;
for (var i:uint=0; i < container.numChildren; i++) {
child = container.getChildAt(i);
trace (indentString, child, child.name);
if (container.getChildAt(i) is DisplayObjectContainer) {
traceDisplayList(DisplayObjectContainer(child), indentString + " ")
}
}
}
diogo
07-19-2006, 08:54 PM
need something like this?
var total:int = numChildren;
for(var i:uint = 0; i < total; i++)
{
trace(getChildAt(i));
}
it returns the type of each object. so to get the instance name of the objects you do the following:
var total:int = numChildren;
for(var i:uint = 0; i < total; i++)
{
trace(getChildAt(i).name);
}
Fall_X
07-21-2006, 12:28 AM
it returns the type of each objectNo it does not. getChildAt returns the actual DisplayObjects. But when tracing them, you off course implicitely call their toString() methods, and that returns something like [object Sprite], which is what's being traced.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.