Skip to content

Instantly share code, notes, and snippets.

@stickupkid
Created May 12, 2011 10:01
Show Gist options
  • Save stickupkid/968275 to your computer and use it in GitHub Desktop.
Save stickupkid/968275 to your computer and use it in GitHub Desktop.
Describe the DisplayList as XML
package utils
{
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.utils.getQualifiedClassName;
/**
*
*/
public function describeDisplayList(displayObject : DisplayObject) : XML
{
var result : XML = <DisplayList />;
var parts : Array;
var qname : String;
var instanceName : String;
if (displayObject is DisplayObjectContainer)
{
const container : DisplayObjectContainer = displayObject as DisplayObjectContainer;
const total : int = container.numChildren;
for (var i : int = 0; i < total; i++)
{
const child : DisplayObject = container.getChildAt(i);
qname = getQualifiedClassName(child);
parts = child.name.split(".");
instanceName = parts[parts.length - 1];
if(child is DisplayObjectContainer)
{
const containerNode : XML = <DisplayObjectContainer qname={qname} name={instanceName} />;
const childContainer : DisplayObjectContainer = child as DisplayObjectContainer;
const childTotal : int = childContainer.numChildren;
if(childTotal > 0)
{
containerNode.@numChildren = childTotal;
const containerDescription : XML = describeDisplayList(childContainer);
for each(var item : XML in containerDescription.child('*'))
{
containerNode.appendChild(item);
}
}
result.appendChild(containerNode);
}
else
{
const subDisplayNode : XML = <DisplayObject qname={qname} name={instanceName} />;
result.appendChild(subDisplayNode);
}
}
}
else
{
qname = getQualifiedClassName(displayObject);
parts = displayObject.name.split(".");
instanceName = parts[parts.length - 1];
const displayNode : XML = <DisplayObject qname={qname} name={instanceName} />;
result.appendChild(displayNode);
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment