The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 15 of 15

Thread: Load External SWF into MovieClip on timeline?

  1. #1

    Load External SWF into MovieClip on timeline?

    I have a flash Project, and I have external SWF's that are loading and unloading into my project. However I need the external SWF's to be under certain layers. What I would love to be able to do is load my external SWF's into a MovieClip that is already residing on the layer underneath those items. However I have no idea how to do this.

    I have the files here. Pretty straight forward, the main SWF ("mod_loading_2.swf"), loads and unloads the other two SWF's("m-1_intro.swf", and "m-2_WIB.swf"). There is a layer named loader layer, and I would like to load the external SWF's into a movieClip on that layer. The load and upload code are in the main SWF, and that is what I need help with.

    How do I load these SWF's into a MovieClip on the timeline?
    Attached Files Attached Files

  2. #2
    1,391
    posts
    Registered User
    Loader instances are basically DisplayObjects - in other words they are just like MC, Sprite, etc - you can add/remove them from the stage just like other DOs - you can also then control the DisiplayList stack by targeting a particular z-order index using the addChildAt() method specifying the object and the index as in:
    addChildAt( theLoaderInstance, 0 ); <- this would place the DO at the bottom-most layer of the z-order

    however, if you want to target a preexisting DO use: theObjectInstance.addChild(theLoaderInstance);

  3. #3
    Another option is to instantiate a Sprite to use as a container for the SWF files.
    Just add it to the displaylist at the desired depth, then add/remove the swf files from it.
    I used to be a paranoid-psychotic-schizophrenic, but don't worry, he's dead now.

  4. #4
    Quote Originally Posted by cbeech View Post
    Loader instances are basically DisplayObjects - in other words they are just like MC, Sprite, etc - you can add/remove them from the stage just like other DOs - you can also then control the DisiplayList stack by targeting a particular z-order index using the addChildAt() method specifying the object and the index as in:
    addChildAt( theLoaderInstance, 0 ); <- this would place the DO at the bottom-most layer of the z-order

    however, if you want to target a preexisting DO use: theObjectInstance.addChild(theLoaderInstance);
    Ok, I tried this, and it looks like my first module is loading into the movieClip on the desired layer, however it breaks my other navigation buttons, so I cannot unload and load the next module.

    It gives me this error:
    Code:
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    	at flash.display::DisplayObjectContainer/removeChild()
    	at mod_loading_2_fla::MainTimeline/MM2_Load()
    	at flash.events::EventDispatcher/dispatchEventFunction()
    	at flash.events::EventDispatcher/dispatchEvent()
    	at M_fla::title1_1/frame45()
    	at flash.display::MovieClip/gotoAndStop()
    	at M_fla::title1_1/next_mod()
    So apparently I need to rescript my buttons and dispatch events from the module that is loaded. So I tried to add movieClip(parent) to my buttons and dispatch events, but that didn't seem to work.

    What do I need to do to get my other listeners to recognize the change?

  5. #5
    Quote Originally Posted by snickelfritz View Post
    Another option is to instantiate a Sprite to use as a container for the SWF files.
    Just add it to the displaylist at the desired depth, then add/remove the swf files from it.
    Sounds interesting, how does this work? And what is the primary difference (pros and cons) between doing this, and just loading into a movieClip?

  6. #6
    Sprite does not have a timeline like MovieClip and is generally preferred for code-based Projects, since it uses slightly less memory than MovieClip.
    I used to be a paranoid-psychotic-schizophrenic, but don't worry, he's dead now.

  7. #7
    Quote Originally Posted by snickelfritz View Post
    Sprite does not have a timeline like MovieClip and is generally preferred for code-based Projects, since it uses slightly less memory than MovieClip.
    Thanks for the info, but I don't think that is going to work for this particular situation. I will keep it in mind for the future though. Thanks!

    Can anyone else help me figure out how to get my buttons to redirect to be able to load and unload. From the loading script in the main FLA, I changed the last function on the first frame to this:

    Code:
    function done(e:Event):void 
    {
    	removeChildAt(0);
    	percent_txt = null;
    	loader_space.addChild(load_mod);
    	gotoAndPlay("M-1_Intro");
    	e.target.content.gotoAndPlay(2);
    	
    }
    WHere "loader_space" is the instance name of the movieClip on my stage that I wan the SWF to load into. That works, and the SWF loads properly.

    However after that, the button in the loaded SWF, M-1_intro.swf, no longer works to load and unload the next SWF. The button sends the playhead to a frame with this dispatch event on it:

    Code:
    MovieClip(parent).dispatchEvent(new Event("MM2_Load", true));
    I tried adding another .parent in there as I figured it is now one more movieClip down, and that didn't work. I also tried removing the MovieClip(parent) altogether, because from what I understand it isn't necessary since dispatch events "bubble up". But that doesn't work either.

    What do I need to do to get my button to work again, and unload the current SWF, and load the second. (without breaking the existing preloader)

    If anyone can help, I would really appreciate it.

    Thanks in advance!

  8. #8
    Actually...

    Isn't there a way to just tell the var "load_mod" to sit at a certain depth?

    Anyone?

  9. #9
    addChildAt(var, depth);
    I used to be a paranoid-psychotic-schizophrenic, but don't worry, he's dead now.

  10. #10
    Quote Originally Posted by snickelfritz View Post
    addChildAt(var, depth);
    That's great!! If I put a number in the depth field, it apparently is setting the external SWF in between layers, however, I can't seem to figure out how it is placing the depth. I have three buttons on the same layer, and two are showing up in front of the external SWF, and the third is behind it. That is with a depth of three. What exactly is the depth referring to?

  11. #11
    depth is exactly what you would think: 0, 1, 2, 3...
    if you want the SWF behind an object (at index 1, for example), set it to the same depth as that object (index 1); the object will move up 1 (index 2).
    I used to be a paranoid-psychotic-schizophrenic, but don't worry, he's dead now.

  12. #12
    Ok, sounds good. So I have some bitmap images on the stage on a certain layer of my project. Some are showing up in front of and some behind the loaded SWF. Clearly they must be on different depths, although they physically exist on the same layer. Can I adjust the depths of these objects?

  13. #13
    Every displayobject is at a separate depth, but some objects are not as "separate" as they might appear in the authoring environment.

    For example, you have three vector shapes drawn on the stage: circle, rectangle, triangle.
    They are all part of the same graphics object.
    In order to create 3 separate shapes, you would have to wrap each one in a MovieClip and name it.
    The drawn shapes then become properties of their respective MovieClips.
    You can then address the MovieClips by name and set their displaylist indexes in AS3.

    Generally speaking, most experienced developers tend to group related elements within Sprites in order to simplify and organize the displaylist.

    For example, you could have a Sprite called background, a Sprite called content, and Sprite called nav.

    • background contains the background elements of the site interface.
      (bitmap backgrounds and UI decorations)
    • content contains the elements that change from page to page.
      (for example, loaded SWF files)
    • nav contains the site navigation system
      (buttons)

    Anything placed in content will always be below nav and above background.
    I used to be a paranoid-psychotic-schizophrenic, but don't worry, he's dead now.

  14. #14
    Okay, so how do I tell a specific MovieClip to be a nav item? And a different movieClip to be a background?

  15. #15
    Simple:
    Code:
    // create the containers
    var background:Sprite = new Sprite();
    var content:Sprite = new Sprite();
    var nav:Sprite = new Sprite();
    
    // add the containers to the displaylist in the order you want them
    // in this case, nav is on top
    addChild(background);
    addChild(content);
    addChild(nav);
    
    // create a new instance of Button
    var button:MovieClip = new Button();
    
    // add button to the nav container
    nav.addChild(button);
    
    // create a new instance of Background
    var bg:BackGround = new Background();
    
    // add bg to the background container
    background.addChild(bg);
    At this point the document class displaylist has three children and two grandchildren:
    index 0 - background > index 0 - bg
    index 1 - content
    index 2 - nav > index 0 - button
    Last edited by snickelfritz; April 17th, 2012 at 03:51 PM.
    I used to be a paranoid-psychotic-schizophrenic, but don't worry, he's dead now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012