【问题标题】:Flex 3, cannot convert SystemManager to SystemManager when loading from server?Flex 3,从服务器加载时无法将 SystemManager 转换为 SystemManager?
【发布时间】:2009-06-15 20:09:01
【问题描述】:

我正在开发一个 AIR 应用程序,该应用程序需要加载、运行和访问从网上提取的 swf 上的方法。过去使用模块效果很好,但由于设计限制,无法用于此应用程序。您可以在下面看到我加载 ImageTest.swf 然后在其上调用函数 Bleh() 的代码。

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

当 swf 是 AIR 应用程序的本地文件时,这可以正常工作,但是当 ImageTest.swf 在服务器上关闭时,它可以正常加载,但我收到强制运行时错误(TypeError: Error #1034: Type Coercion failed: cannot将 _Engine_mx_managers_SystemManager@7c36281 转换为 mx.managers.SystemManager) 在该行:

SystemManager(event.target.content).addEventListener(FlexEvent.APPLICATION_COMPLETE, swfAppComplete);

我认为该错误可能与安全沙盒问题有关,但我不确定。提前致谢!

【问题讨论】:

    标签: apache-flex actionscript-3


    【解决方案1】:

    这与安全问题有关,您的 AIR 应用程序有 APPLICATION 安全沙箱,但加载的 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 );
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-02
      • 2019-04-19
      相关资源
      最近更新 更多