Question
Accessing a class from a loaded SWF
In Flash Professional, I drew a shape, converted it to symbol, linked it to class Symbol1 (extends MovieClip) which is generated at run-time, and saved the SWF file as shape.swf.
Now my main application wants to load shape.swf and create multiple instances of Symbol1 but I get ReferenceError when trying to access the class Symbol1.
Below is my main application's code. Errors thrown are mentioned in comments.
public class MovieClipTest extends Sprite
{
public function MovieClipTest()
{
var url:String = 'shapes.swf';
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, f);
l.load(new URLRequest(url), new LoaderContext(false, ApplicationDomain.currentDomain));
}
private function f(event:Event):void
{
var content:Sprite = (event.currentTarget as LoaderInfo).content as Sprite;
trace(getQualifiedClassName(content.getChildAt(0))); // output: Symbol1
trace(ApplicationDomain.currentDomain.getDefinition('Symbol1')); // throws Error #1065: Variable Symbol1 is not defined.
trace(getDefinitionByName('Symbol1')); // throws Error #1065: Variable Symbol1 is not defined.
}
}