PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Multiple Loaders wont overlap?
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: [RESOLVED] Multiple Loaders wont overlap?

  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    82

    resolved [RESOLVED] Multiple Loaders wont overlap?

    I have a menu swf with multiple buttons and an animated logo which is in a loader called myLoader

    These buttons are in an MC which uses this

    Actionscript Code:
    function buttonClick(event:MouseEvent):void
    {
        var myLoader:Loader = new Loader();
        myLoader.x = -155
        myLoader.y = -355
        myLoader.load(new URLRequest(event.target.name + ".swf"));
        addChild(myLoader);

    ...and so on with the add.event.listeners and they all work great- they overlap the menu then disapear.

    The problem I have is the logo always stays on top of everything. Looks rather stupid, is there a way I can hide this logo behind the swfs while they play?

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That function uses a new Loader every time you click. You didn't post how you're removing them later, but apparently you are. If you only want one loaded item (logo, and whatever these load) at a time, then re-use the same loader instead. To do that, make sure that myLoader is declared at a larger scope, then remove this line:
    Code:
    var myLoader:Loader = new Loader();
    That will make the rest of the function reuse the larger-scoped myLoader. When you load new content into the same loader, it replaces the old content.

    If that's not what you want, then just make sure that the container you are adding your loaders to is on top of your logo. To do that, just add it after you add the logo. The last added child (of the same parent) is on top of previously added children.

  3. #3
    Member
    Join Date
    Mar 2009
    Posts
    82
    Im not very good at AS yet but what I have is the logo script on the first frame of the menu whereas the script for the other loaded SWFs are in the MCs first frame.

    Am I going about this the wrong way?

    Should I have all my script on the first frame of the menu?

  4. #4
    Member
    Join Date
    Mar 2009
    Posts
    82
    How do I declare myLoader at a larger scope?

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Do it at the same level as the function, rather than inside the function.
    Code:
    var myLoader:Loader = new Loader();
    myLoader.x = -155
    myLoader.y = -355
    addChild(myLoader);
    
    function buttonClick(event:MouseEvent):void
    {
        myLoader.load(new URLRequest(event.target.name + ".swf"));
    }

  6. #6
    Member
    Join Date
    Mar 2009
    Posts
    82
    I seem to get this when i use your coding:

    Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

    However, it still runs fine behind that error. Im confused.

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Trace what it's trying to load. I'm guessing that the target is not what you think it is.
    Code:
    function buttonClick(event:MouseEvent):void
    {
        trace("target name: "+event.target.name);
        myLoader.load(new URLRequest(event.target.name + ".swf"));
    }
    If that comes up with something like "instance114", then the target is some unnamed thing inside your button. You can use currentTarget rather than target to get the object you added the listener to.

  8. #8
    Member
    Join Date
    Mar 2009
    Posts
    82
    So I've done the trace and all my swfs trace fine except the first one has this:

    Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

    I'm not sure why because all my swf files are simply text with attached sound files so basically just movies. They have all been done in the same manner. Could it be a missing URL to one of the sound files?

  9. #9
    Member
    Join Date
    Mar 2009
    Posts
    82
    I found the problem, it was script i had forgotten about a while back calling an earlier version of the swfs.

    So I've used your advice and it works geat, however, the sign is now in the middle of the screen, how can I move the sign without moving the loaded swfs?

    This is what I have:
    Actionscript Code:
    var myLoader:Loader = new Loader();
    myLoader.x = -155
    myLoader.y = -355
    addChild(myLoader);
       
    function buttonClick(event:MouseEvent):void
    {  
        //trace("target name: "+event.target.name);
        myLoader.load(new URLRequest(event.target.name + ".swf"));
    }

    1.addEventListener(MouseEvent.CLICK, buttonClick);
    2.addEventListener(MouseEvent.CLICK, buttonClick);
    3.addEventListener(MouseEvent.CLICK, buttonClick);
    4.addEventListener(MouseEvent.CLICK, buttonClick);
    5.addEventListener(MouseEvent.CLICK, buttonClick);
    6.addEventListener(MouseEvent.CLICK, buttonClick);


    myLoader.load(new URLRequest("Sign.swf"));
    addChild(myLoader);

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Do you seriously have instances named "1", "2", etc? And that code works? That's surprising.

    If you want the first thing loaded to be in a different place, then set the loader's coordinates where that should be at the beginning. Then you can reset the coordinates where you want the other stuff inside the buttonClick handler.

  11. #11
    Member
    Join Date
    Mar 2009
    Posts
    82
    Well, no my instances are called something else but for privacy reasons they are 1,2..etc. My instances are to the coords specified at the first child, but I need the Sign to be at another coord.

    What happens is this script is on a menu, it has an MC with these buttons and this script. When the buttons are clicked the corresponding SWFs 1,2..etc are loaded. When they finish they close and the user is back at the menu to continue on to the next. The Sign is supposed to appear on the menu at all times, its an animated logo. The loaded SWFs are supposed to appear over the Sign when they play. Does this make sense?

    Greatly appreciate the help and advice. Thanks

  12. #12
    Member
    Join Date
    Mar 2009
    Posts
    82
    Found a solution that works. Thanks for your help.
    Code if someone was curious how to fix it, is here:

    Actionscript Code:
    var myLoader:Loader = new Loader();
    var myLoader2:Loader = new Loader();

    function buttonClick(event:MouseEvent):void
    {  
        //trace("target name: "+event.target.name);
        myLoader.load(new URLRequest(event.target.name + ".swf"));
        myLoader.x = -155
        myLoader.y = -355
        addChild(myLoader);
    }

    1.addEventListener(MouseEvent.CLICK, buttonClick);
    2.addEventListener(MouseEvent.CLICK, buttonClick);
    3.addEventListener(MouseEvent.CLICK, buttonClick);
    4.addEventListener(MouseEvent.CLICK, buttonClick);
    5.addEventListener(MouseEvent.CLICK, buttonClick);
    6.addEventListener(MouseEvent.CLICK, buttonClick);


    myLoader2.load(new URLRequest("Sign.swf"));
    myLoader2.x = -250
    myLoader2.y = -466
    addChild(myLoader2);

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