dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Load External SWFs, addChild(Loader) vs. addChild(Loader.content), etc.

  1. #1
    Senior Member
    Join Date
    Jan 2006
    Posts
    133

    Question Load External SWFs, addChild(Loader) vs. addChild(Loader.content), etc.

    Hello All,
    After doing a lot of reading on loading external assets, the Loader class, etc. I just need some clarification and maybe a little guidance.

    I have a main "shell" swf which, by clicking several buttons, will load/unload various external swfs into a Placeholder_mc which resides on the main timeline in Shell.swf

    In the documentation and tutorials I've seen a couple different methods, and I'm not sure I quite understand the difference, or at least the reason you would use one over the other...

    In the 1st method, you can just add the Loader object using the addChild() method:

    Code:
    var myLoader:Loader = new Loader();
    var myURLRequest:URLRequest = new URLRequest("ExternalFileA.swf");
    myLoader.load(myURLRequest);
    Placeholder_mc.addChild(myLoader);
    This will apparently add myLoader to the display list once it has completely loaded.

    The 2nd method, you supposedly can add the Loader.content; however, it appears you can only do this once the content has completed loading, so you need to incorporate an event handler with the contentLoaderInfo object:

    Code:
    var myLoader:Loader = new Loader();
    var myURLRequest:URLRequest = new URLRequest("ExternalFileA.swf");
    myLoader.load(myURLRequest);
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, Loaded);  
    
    function Loaded(evt:Event):void{ 
        Placeholder_mc.addChild(myLoader.content);  
    }
    What are the pros/cons of adding the entire Loader object, as opposed to the Loader.content and vice versa??

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    I don't know where you saw the second method, but i have never seen anybody using that. Definitely I would add the Loader to the Display list, since you can remove the content without removing the Loader itself. you can unload the content or load new content.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Junior Member
    Join Date
    Jul 2009
    Posts
    14

    loading 2 swf with 1 swf is over 2 swf

    Hi

    I am just started using Flash CS4 / AS3.

    I am loading 2 swf files in another flash file

    see http://64.131.70.95/~archit/flashdemo/final.html

    1st swf is also created by actionscript 3

    2nd swf (cloud scene) is created by actionscript 3

    Now I am loading both swf in final flash file.


    1st swf in layer 3(above layer1). Action has following script

    ==================================
    var myLoader:Loader = new Loader();
    addChild(myLoader);
    var url:URLRequest = new URLRequest("CloudExampleLogoCS3Final.swf");
    myLoader.load(url);
    =======================================



    2nd swf in layer 1(below layer3). Action has following script

    ==================================
    var myLoader1:Loader = new Loader();
    addChild(myLoader1);
    var url1:URLRequest = new URLRequest("CloudExampleCS3Final.swf");
    myLoader1.load(url1);
    =======================================

    I want 1 swf is above 2 swf. (Text above cloud).

    How to do this?

    Earlier we used level in early version of flash but it is removed from AS3.

    Thx
    Last edited by websoftexpert; 07-31-2009 at 03:15 AM.

  4. #4
    Junior Member
    Join Date
    Jul 2009
    Posts
    14
    hi

    Can you help me by replying my post at http://board.flashkit.com/board/show....php?t=799885?

    thx

  5. #5
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    swapChildren(myLoader,myLoader1);
    Last edited by cancerinform; 07-31-2009 at 03:29 AM.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  6. #6
    Junior Member
    Join Date
    Jul 2009
    Posts
    14
    Hi

    I tried. Its not working.

    here is code I modified after your reply.


    ======================================

    Code:
    var myLoader:Loader = new Loader(); 
     addChild(myLoader); 
     var url:URLRequest = new URLRequest("CloudExampleLogoCS3Final.swf"); 
     myLoader.load(url);
    /*loadMovieNum("CloudExampleLogoCS3.swf", 10); */
     var myLoader1:Loader = new Loader(); 
     addChild(myLoader1); 
     var url1:URLRequest = new URLRequest("CloudExampleCS3Final.swf"); 
     myLoader1.load(url1); 
    swapChildren(myLoader,myLoader1);
    =========================================

    The above code is written in single layer.

    Plz see attached zip file.

    thx
    Last edited by websoftexpert; 11-20-2009 at 12:02 AM.

  7. #7
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    PHP Code:
    const logoLoader:Loader = new Loader();
    const 
    cloudLoader:Loader = new Loader();
    const 
    logoURL:URLRequest = new URLRequest("CloudExampleLogoCS3Final.swf"); 
    const 
    cloudURL:URLRequest = new URLRequest("CloudExampleCS3Final.swf"); 

    logoLoader.load(logoURL);
    cloudLoader.load(cloudURL);

    addChild(cloudLoader);    //  bottom
    addChild(logoLoader);    //  top 

  8. #8
    Junior Member
    Join Date
    Jul 2009
    Posts
    14
    its not working. see attachment.

    sample 1 is working as it doesn't contains cloud script.

    sample 2 is working as it does contains cloud script.

    I think issue is with cloud script.


    thx
    Last edited by websoftexpert; 11-20-2009 at 12:02 AM.

Tags for this Thread

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