I have a simple Flash document with a single rectangle on a stage. I've made the rectangle a symbol, a MovieClip, and set its instance name to "test_symbol_name". I've published this document to a .swf. (Here's the .fla and .swf)
In an AS3 Flash Builder project I load the swf with a Loader, then trace everything on it's display list with this function:
public static 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.parent.name + " " + indentString + " " + child.name);
if (container.getChildAt(i) is DisplayObjectContainer) {
traceDisplayList(DisplayObjectContainer(child), indentString + "->");
}
}
}
Here's the output:
-> instance471 -> instance472
->-> instance472 ->-> instance473
->-> instance472 ->-> test_symbol_name
->->-> test_symbol_name ->->-> instance474
My symbol has become nested inside instance472, which is inside instance471.
I can reach the symbol in code by specifying the containing symbol (472), like this:
var myTestSymbol:MovieClip = (loader.getChildByName('instance472') as DisplayObjectContainer).getChildByName('test_symbol_name') as MovieClip;
Here's my questions
What are instance472 and instance471? Are they the document and the stage, or something else?
When I publish the swf, the instance number can change. I have to adjust my code to match the latest number to get it to work. How can I name instance471?
Is this the right approach, or is there a better way to reach my symbol instance?