8 Replies Latest reply on Jun 14, 2009 9:54 AM by kglad

    Remove Loader

    DJ Foosh

      Hi -

       

      I am so grateful for this Forum - thank you in advance for all your great input!

       

      I am loading .swf files in with this code (via buttons):

       

      var phoLoader:Loader=new Loader();

      photos_btn.addEventListener(MouseEvent.CLICK, photos);

      function photos(myevent:MouseEvent):void {

      var myURL:URLRequest=new URLRequest("lore_photos.swf");

      phoLoader.load(myURL);

      phoLoader.x = 0

      phoLoader.y = 0

      addChild(phoLoader);

      }

       

      var mmLoader:Loader=new Loader();

      mm_btn.addEventListener(MouseEvent.CLICK, mimo);

      function mimo(myevent:MouseEvent):void {

      var myURL:URLRequest=new URLRequest("mm.swf");

      mmLoader.load(myURL);

      mmLoader.x = 0

      mmLoader.y = 0

      addChild(mmLoader);

      }

       

      staff_btn.addEventListener(MouseEvent.CLICK, unloadcontent);

      function unloadcontent(myevent:MouseEvent):void {

      removeChild(mmLoader);

      }

       

      var staffLoader:Loader=new Loader();

      staff_btn.addEventListener(MouseEvent.CLICK, staf);

      function staf(myevent:MouseEvent):void {

      var myURL:URLRequest=new URLRequest("staff.swf");

      staffLoader.load(myURL);

      staffLoader.x = 0

      staffLoader.y = 0

      addChild(staffLoader);

      }

       

      mm_btn.addEventListener(MouseEvent.CLICK, unloadstaff);

      function unloadstaff(myevent:MouseEvent):void {

      removeChild(staffLoader);

      }

       

      When I test the main .fla (which contains the code), I get this error message - even though everything is working fine - what does it mean? What's a "caller"? 

       

      ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

      at flash.display::DisplayObjectContainer/removeChild()

      at davon_fla::MainTimeline/unloadstaff()

        • 1. Re: Remove Loader
          kglad Adobe Community Professional & MVP

          it means one of your removeChild() methods is problematic.  in particular, the caller (ie, the supposed parent) is not the parent of the supposed child.

           

          ie, in your situation, one of your loaders hasn't been added to a parent or has already been removed.

          1 person found this helpful
          • 2. Re: Remove Loader
            DJ Foosh Level 1

            Thank you.

             

            I think I need to add an if statement.  As in:  if xyzLoader has been loaded then remove it, if not then do not execute the removechild function (when the "other" button is clicked.  The question is how to properly code this.  I am (re)searching...

            • 3. Re: Remove Loader
              kglad Adobe Community Professional & MVP

              you can any displayobject to see if its parent property is null:

               

              if(xyzLoader.parent!=null){

              removeChild(xyzLoader);  // assuming the parent is the current scope

              }

              • 4. Re: Remove Loader
                DJ Foosh Level 1

                Hey - tried various options but still getting error messages.  Maybe it's because it's a .swf file within a .swf file, because clicking on the buttons in the About section of the site doesn't wipe the slate clean like when I click on the main navigation buttons of the site.

                 

                If you go to the site:   www.loreleynyc.com/loreleynyc.com_neu   and click on About and then on Staff and then on Michael Momm you will see that they overlap.  I guess because it's a movie within a movie it doesn't automatically clean the slate like it does with the "main navigation" buttons and pages of the site.  I'll try a different way now, on the timeline, because i gotta get this site up, but it must be possible with Actionscript, no?

                 

                Also, see the html at the bottom, how can I make the margin to the .swf file bigger?

                 

                Thanks a million!

                 

                I have attached the .fla files aswell, saved in CS3

                • 5. Re: Remove Loader
                  DJ Foosh Level 1

                  trying attaching files again

                  • 6. Re: Remove Loader
                    DJ Foosh Level 1

                    it doesn't let me upload the .fla files for some reason...

                    • 7. Re: Remove Loader
                      kglad Adobe Community Professional & MVP

                      i'm sure it's possible with actionscript.

                      • 8. Re: Remove Loader
                        kglad Adobe Community Professional & MVP

                        try zipping, after browsing for your file and clicking ok wait a minute of so.  then try post message.