views:

145

answers:

2

This is a AS3 project created in FlashDevelop. It targets flash player 10. I have a disturbing problem when running this code:

package 
{
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLRequest;

    public class Main extends MovieClip
    {
        private var loader:Loader;
        private var sprite:Sprite;

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init); }

        private function init(e:Event = null):void {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingDone);

            loader.load(new URLRequest('loadIn.swf')); // error occurs when loading this file.
            //loadIn.swf is compiled with all the code in this file but with the loader-parts commented out...

                    // just a Adobe Flash created graphic, no problems loading this one
            //loader.load(new URLRequest('waitingPopup.swf')); 

            //sprite = new Sprite();
            //sprite.graphics.beginFill(0xFF0000);
            //sprite.graphics.drawRect(0, 0, 490, 356);
            //sprite.graphics.endFill();
            //addChild(sprite);
        }
        private function loadingDone(e:Event):void {
            trace(loader.contentLoaderInfo.contentType);        // application/x-shockwave-flash
            trace(loader.contentLoaderInfo.parentAllowsChild);  // true
            trace(loader.contentLoaderInfo.sameDomain);         // true
            trace(loader.contentLoaderInfo.swfVersion);         // 10
            trace(loader.contentLoaderInfo.content);        // [Object Main]

            //this is were everything goes south
            addChild(e.target.content); 
        }
    }
}

Now, what I can gather from the debug window, what happens is that the swf restarts itself and just ends up in a loop when i try to call the addChild()-method. All that is shown in my output window is:

[SWF] C:\svn\Development\TestProject\bin\loadIn.swf - 1 797 bytes after decompression.
application/x-shockwave-flash
true
true
10
[object Main]

Any ideas what could create such a strange loop and error? I´ve been trying to solve it all day. Maybe some kind of settings in FlashDevelop or parameters to the MXMLC compiler?

Thankful for all answers!

A: 

It might help if you remove the LoadingDone listener before adding the child. Maybe the COMPLETE event of the second loaded swf bubbles up to the main clip and retriggers another load:

private function loadingDone(e:Event):void {
    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadingDone);
    addChild(e.target.content); 
}

l

Quasimondo
Tried that as well and it didnt work, but thanks for the suggestion! Now I´m thinking that the problem might be that the files have a main class with the same name...
Tobias
A: 

If they do have the same name and you're not able or don't want to change the name, try loading the file with a new applicationDomain in the LoaderContext of your URLRequest: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/system/LoaderContext.html That should resolve any conflicts.

DHuntrods
thanks alot! solved my problems! Turns I had quite a bit of namespace collision between the loaded swf and my main swf, I had no idea that flash was so sensitive to this. I found it strange that I don´t recieve an error though when loading a file whose main class has the same name as my main swf, which (i guess) ends up calling the main class of my main swf => loop :)thanks again!
Tobias
Glad to hear it! =)
DHuntrods