Per Sommer

code

AS3 Trace path back to root

by admin on Jul.15, 2008, under as3, code, snippet

This function will trace the path DisplayObject for a DisplayObject back to root in Actionscript 3. Useful for seeing witch containers it’s belonging to.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private function tracePath (dispObj : DisplayObject, s : String = "") : void
{
	if(dispObj.parent != null)
	{
		tracePath(dispObj.parent, s + "." + dispObj.name);
	}
	else
	{
		var a : Array = s.split(".").reverse();
		var output : String = "";
		for (var i : Number = 0;i < a.length; i++) 
		{
			output = output + "." + a[i];
		}
		trace("PATH: " + output.substr(1, output.length - 2));
	}
}

Usage example:

1
2
objName.name = "myDisplayObjectTest"
tracePath(objName);

Output example:

1
PATH: root1.movPreloaderHolder.loaderHolder.instance3.myDisplayObjectTest
1 Comment : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...