Thursday, July 26, 2007

how do i find the path to where a MC belongs

source 1:
http://www.kirupa.com/forum/showthread.php?p=1935107

Hello :)

in AS3 i don't find a native method ?

For the moment you can test :

package
{

import flash.display.* ;

public class test extends Sprite
{

/**
* Creates a new test instance.
*/
public function test()
{

var container:Sprite = new Sprite() ;

var container2:Sprite = new Sprite() ;
container2.graphics.beginFill(0xFF0000, 1) ;
container2.graphics.drawCircle(0, 0, 150) ;

addChild(container) ;
container.addChild(container2) ;

var target:String = getDisplayPathName(container2) ;

trace( target ) ;

}

static public function getDisplayPathName( display:DisplayObject
):String
{

var parents:Array = [] ;
var parent:* = display ;

while( true )
{
parents.push( parent.name ) ;
parent = parent.parent ;
if (parent.name == null)
{
break ;
}
}

parents.reverse() ;

return parents.join( "." ) ;

}

}

but it's not the better solution lol

eKA+ :)

No comments: