sefiroths
sefiroths

Reputation: 1563

get position of instance of the same type in the stage

hi i'd like to count and get position of instance of the same type in the stage. i have tried:

var target; 
for(var item in _root){     
if(_root[item] instanceof MovieClip ||   _root[item] instanceof TextField){         
target = _root[item];         
trace("ITEM: "+target);         
trace("X: "+target._x);         
trace("Y: "+target._y);         
trace("----------------");     } }

but it says access to property _root undefined, and instanceof deprecated how can i make it? thanks

Upvotes: 0

Views: 411

Answers (1)

Björn Kechel
Björn Kechel

Reputation: 8463

in as3 you can loop through all children of your stage (or parent movieclip):

for (var i : int = 0;i < stage.numChildren;i++) 
{
    var displayObject : DisplayObject = stage.getChildAt(i);
    if(displayObject is TextField || displayObject is MovieClip)
    {
        trace("ITEM: " + displayObject);         
        trace("X: " + displayObject.x);         
        trace("Y: " + displayObject.y);         
        trace("----------------");
    }
}

Upvotes: 1

Related Questions