6 Replies Latest reply: May 8, 2012 2:24 PM by saratogacoach RSS

    Cleaning up the stage

    saratogacoach Community Member

      Hi,

       

      I have a stage to which a complex animation is added, including one step in the process: addChild(bitmapxyz).

       

      At the end of this animation, I need to give the viewer the option of closing it, removing  the added items, in order to start and view other animations.

       

      Tried without success: 

       

      stage.removeChild(bitmapxyz);

       

      Get an 1120 error.

       

      Not sure how to clean up the stage for this animation? Or maybe there's a way to create a child of the primary stage to hold the animation, then remove this stage.child? If this could work, can someone point me to how to add a child to a stage that then can hold what currently is being added to the stage?

       

      Any help appreciated.

       

      Regards,

        • 1. Re: Cleaning up the stage
          Rob Dillon MVP

          You can create an instance of Sprite that can then hold all of the child objects that you want to put on the stage.

           

          var stuffHolder:Sprite = new Sprite();

          addChild(stuffHolder);

          stuffHolder.addChild(childname);

          stuffHolder.addChild(otherChildName);

           

          Then, when you want to remove everything, you can just remove the sprite. This will remove everything that it contains.

           

          removeChild(stuffHolder);

           

          If you want to keep that Sprite around for some reason, then just move it off the visible area of the stage.

          • 2. Re: Cleaning up the stage
            saratogacoach Community Member

            Hi Rob,

             

            Thanks for this suggestion. Did some reading on it, so a good learning experience for me. And, a good thing to know about.

             

            I ended up sorting it out another way. But it is finally working OK.

             

            Regards,

            • 3. Re: Cleaning up the stage
              sinious MVP

              In the future you can assign an instance name to a clip and then access it like that. If you don't want to keep references around then this is an easy way to access it again.

               

              e.g.

               

              var someObj:MovieClip = new SomeLibraryObject(); // create a new instance of something in your library

              someObj.name = "myObject"; // assign that instance a name

              addChild(someObj); // add it to the display list

               

              You can now access that clip some time later using the getChildByName() method as long as you have access to the stage its on. For instance:

               

              removeChild( getChildByName("myObject") );

              • 4. Re: Cleaning up the stage
                saratogacoach Community Member

                Hi,

                 

                Thank you for this explanation. I'm sure to find it useful as I continue to learn how to script in AS3.

                 

                Regards

                • 5. Re: Cleaning up the stage
                  sinious MVP

                  http://gotoandlearn.com/ has a lot of good video tutorials on a range of subjects. Take a peek. The display list is something you'll probably work with the most in anything you do in Flash.

                  • 6. Re: Cleaning up the stage
                    saratogacoach Community Member

                    Thank you once again. Looks like a good resource for learning!