I have an existing AIR app whose main content is App.swf. I would like to have another AIR app that hosts and runs App.swf. When I say run it, I mean displays it's WindowedApplication.
Here's the code for the 2 AIR projects (imports are omitted for brevity):
// App AIR Project -> App.mxml -> App.swf (it's just a window)
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
public function doSomething():void {
trace("doSomething called");
}
]]>
</mx:Script>
</mx:WindowedApplication>
// AirAppHostApplication AIR Project -> AirAppHostApplication.mxml -> AirAppHostApplication.swf
<?xml version="1.0" encoding="utf-8"?>
<custom:AirAppHostApplication xmlns:custom="components.*" />
// components/AirAppHostApplication.as
public class AirAppHostApplication extends WindowedApplication
{
private var ldr:Loader;
public function AirAppHostApplication()
{
addEventListener (FlexEvent.CREATION_COMPLETE, handleComplete);
}
private function handleComplete( event : FlexEvent ) : void
{
loadSwf("App.swf");
}
private function loadSwf(swf:String):void {
ldr = new Loader();
var req:URLRequest = new URLRequest(swf);
var ldrContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
ldr.load(req, ldrContext);
}
private function completeHandler(event:Event):void {
var appSystemManagerCls:* = ApplicationDomain.currentDomain.getDefinition("_app_mx_managers_SystemManager") as Class;
var appSystemManagerInstance:* = new appSystemManagerCls(Application.application);
var appInstance:WindowedApplication = appSystemManagerInstance.create();
appInstance.activate();
appInstance.doSomething();
}
}
I get the following error while App.swf is being loaded:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.managers::SystemManager/initHandler()[C:\autobuild\galaga\frameworks\projects\framework\src\mx\managers\SystemManager.as:3001]
I believe the issue has to do with AirAppHostApplication's SystemManager conflicting with App's SystemManager because they are both living in the same app domain. Can an AIR app be written where a WindowedApplication class isn't statically defined, but loaded at runtime by loading a swf and instantiating the WindowedApplication subclass that's contained in the swf.
The reason I want to do this is for an automation scenario where I have to assume I don't have the source code for the app I'm automating, but I do have access to the names of the public classes and their public methods exposed for automation. I have complete control over the environment and don't have to deal with any constraints around that, so I can put 2 AIR apps in the same directory, etc.
Is this possible?