I am working on an AIR application that needs to download, run and access a SWF file from the network. Using modals worked well in the past, but due to design limitations, this application is not possible. Below you can see the code where I load ImageTest.swf and then call the Bleh () function.
private var l:Loader = new Loader();
private var ctx:LoaderContext;
private function onInit():void
{
l.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
l.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onLoadError);
l.load(new URLRequest("ImageTest.swf"));
}
private function onLoadError(event:IOErrorEvent):void
{
}
private function onLoadComplete(event:Event):void
{
ui.addChild(event.target.content);
SystemManager(event.target.content).addEventListener(FlexEvent.APPLICATION_COMPLETE, swfAppComplete);
}
private function swfAppComplete(event:FlexEvent):void
{
var sys:SystemManager = SystemManager(event.currentTarget);
var app:Object = sys.application;
app.Bleh();
}
This works fine when swf is local to the AIR application, but when ImageTest.swf is disabled on the server, it loads normally, but I get a coercion runtime error (TypeError: Error # 1034: Type Coercion failed: can not convert _Engine_mx_managers_SystemManager @ 7c36281 to mx.managers.SystemManager) in line:
SystemManager(event.target.content).addEventListener(FlexEvent.APPLICATION_COMPLETE, swfAppComplete);
, , . !
Max