A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Loading an external SWF

  1. #1
    Junior Member
    Join Date
    Nov 2007
    Location
    New England
    Posts
    13

    resolved [RESOLVED] Loading an external SWF

    Hello.

    I'm making a webpage, and trying to have one main SWF, that then loads other SWFs (the various content pages) on the press of a button.

    It seems to be working, except that the loaded SWF displays crammed up in the upper left corner, instead of in the middle of the page where I have the loader MC. Infact, even if I delete the loader MC instance, the loaded SWF still displays the same. (Which tells me that I have a disconnect somewhere.)

    Code:
        import flash.events.Event;
        import flash.events.IOErrorEvent;
        import flash.net.URLLoader;
        import flash.net.URLRequest;
        import flash.display.Loader;
    
    var swfLoader0 = new Loader();
        var urlReq0:URLRequest = new URLRequest("Content000.swf");
        swfLoader0.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadComplete0);
        swfLoader0.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, swfLoader0ror);
        swfLoader0.load(urlReq0);
        function swfLoadComplete0(evt:Event):void
        {
        var loader:Loader = Loader(evt.target.loader);
        addChild(loader.content);
        swfLoader0.removeEventListener(Event.COMPLETE, swfLoadComplete0);
        }
                
        function swfLoader0ror(evt:IOErrorEvent):void
        {
          trace("Unable to load swf ");
          swfLoader0.removeEventListener(IOErrorEvent.IO_ERROR, swfLoader0ror);
        }
    stop();
    swfLoader0 is the instance name of the loader MC, which is an empty movie clip.

    How can I control where the loaded SWF displays?

    (Sorry if this is a dumb question, I just switched to AS3, and my brain is still in AS2 mode)

    Thank you.
    Last edited by Asymptote; 07-29-2011 at 01:15 PM.
    The problem with being the office expert on something, is you have no one to talk to when you have a problem...

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You have redeclared swfLoader0. In the above code, it is not the MovieClip with the name "swfLoader0", it is a new Loader.

    Change the name of your on-stage holder clip. Call it something like "mcHolder". Then add your content to that instead of the main timeline. Change the addchild line to:
    Code:
    mcHolder.addChild(loader.content);

  3. #3
    Junior Member
    Join Date
    Nov 2007
    Location
    New England
    Posts
    13
    Thank you, that fixed it!
    The problem with being the office expert on something, is you have no one to talk to when you have a problem...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center