Flex 3, cannot convert SystemManager to SystemManager when booting from the server?

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);

, , . !

+3
1

, AIR APPLICATION Security, SWF . , SWF AIR, allowLoadBytesCodeExecution.

:

    private function loadApp() : void {
        var urlLoader : URLLoader = new URLLoader();
        urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
        urlLoader.addEventListener( Event.COMPLETE, onAppLoaded );
        urlLoader.load( new URLRequest( url ) );
    }

    private function onAppLoaded( event : Event ) : void {
        var appLoader : Loader = new Loader();
        var context : LoaderContext = new LoaderContext();
        // don't assign currentDomain as applicationDomain here
        // it will UNABLE to unload swf later 
        context.applicationDomain = ApplicationDomain.currentDomain;
        context.allowLoadBytesCodeExecution = true;
        appLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, onAppExecuted );
        appLoader.loadBytes( ByteArray( ( event.currentTarget as URLLoader ).data ), context );
    }

    private function onAppExecuted( e : Event ) : void {
        content = SystemManager( LoaderInfo( e.target ).content );
        content.addEventListener( FlexEvent.APPLICATION_COMPLETE, onLoadedAppInitComplete );
    }
0

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


All Articles