简体   繁体   English

Flex:当我加载本地外部SWF时,应用程序会无限加载/卸载

[英]Flex: When I load a local external SWF, the application load-unload infinitely

I have a Flex application that just load an external SWF, but the application load and unload infinitely my swf. 我有一个Flex应用程序,它仅加载外部SWF,但是该应用程序无限加载和卸载我的SWF文件。

The embeded as3 code is: 嵌入的as3代码为:

<![CDATA[

        import mx.events.FlexEvent;

        private var m_Application:Application;

        private function initGenderMenuApp(evt:FlexEvent):void{ 

            m_Application = evt.target as Application;
            m_Application.removeEventListener( FlexEvent.APPLICATION_COMPLETE, initMenuApp );
            var loader:Loader = new Loader();

            trace("initApp");
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onFailedLoad);
            loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoadedApp );
            loader.load( new URLRequest( "application.swf" ));

        }
        private function onFailedLoad( evt:Event ):void{

            trace("ERROR", evt.target);
        }

        private function onLoadedApp( evt:Event ):void{


            trace("Loading Application..");
            var loaderInfo:LoaderInfo = evt.target as LoaderInfo;
            loaderInfo.removeEventListener( Event.COMPLETE, onLoadedApp);
            trace(loaderInfo.loader.content);
            m_Application.addElement( new SpriteUIComponent( evt.target.loader.content as MovieClip));          
        }

    ]]>

SpriteUIComponent is used to add the SWF as Sprite on the stage. SpriteUIComponent用于将SWF作为Sprite添加到舞台上。

Regards 问候

Are you trying to load the same application.swf as the main app itself?? 您是否要加载与主应用程序本身相同的application.swf? (Recursion???) (递归???)

You can add 2 extra events to better monitor what's happening with the loading. 您可以添加2个额外的事件,以更好地监视加载过程。 These two are HTTPStatusEvent.HTTP_STATUS and ProgressEvent.PROGRESS . 这两个是HTTPStatusEvent.HTTP_STATUSProgressEvent.PROGRESS

They are used in this fashion: 它们以这种方式使用:

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

private function progressHandler(event:ProgressEvent):void {
    trace("progressHandler: bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
}

private function httpStatusHandler(event:HTTPStatusEvent):void {
    trace("httpStatusHandler: " + event);
}

Now you will have better control over what happens. 现在,您将可以更好地控制发生的情况。 You will see how many bytes that are loaded until the loading is done and you will see if there are any http errors. 您将看到在加载完成之前已加载的字节数,并查看是否有任何http错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM