1
votes

I have a Flex application that just load an external SWF, but the application load and unload infinitely my swf.

The embeded as3 code is:

<![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.

Regards

2
What does your tracing look like? "initApp", "Loading Application.."?rzetterberg

2 Answers

0
votes

Are you trying to load the same application.swf as the main app itself?? (Recursion???)

0
votes

You can add 2 extra events to better monitor what's happening with the loading. These two are HTTPStatusEvent.HTTP_STATUS and ProgressEvent.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.