An AIR application that downloads and runs an existing AIR swf

I have an existing AIR application whose main content is App.swf. I would like to have another AIR application that hosts and runs App.swf. When I say run it, I mean display it WindowedApplication.

Here is the code for 2 AIR projects (import reduced for brevity):

// App AIR Project -> App.mxml -> App.swf (it 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();
    }   
}

When loading App.swf, the following error appears:

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 problem is with the AirAppHostApplication SystemManager, which conflicts with the App SystemManager, because they both live in the same application domain. Can an AIR application be written where the WindowedApplication class is not statically defined but loaded at runtime by loading swf and subclassing WindowedApplication contained in swf.

, , - , , , , , . , - , 2 AIR ..

?

+3
2

, . http://blog.everythingflex.com/2009/06/08/open-an-air-application-from-a-2nd-air-application/

" AIR" AIR.

:

, , , , , allowBrowserInvocation AIR, true, , .

id . , LauncherSample, , AIR:

plus , .

Adobe .

1009 .

, null, . ( ) . , , Sprite. Sprite ( addChild() DisplayObjectContainer), stage null. , , Sprite :

import flash.display.Sprite;
var sprite1:Sprite = new Sprite();
var q:String = sprite1.stage.quality;
+2

, . AIR . - , .

0

Source: https://habr.com/ru/post/1733478/


All Articles