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

    Cleaning up the stage

    saratogacoach Newcomer



      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: 




      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.



        • 1. Re: Cleaning up the stage
          robdillon Ninja

          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();





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




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

          1 person found this helpful
          • 2. Re: Cleaning up the stage
            saratogacoach Newcomer

            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.



            • 3. Re: Cleaning up the stage
              sinious Ninja

              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.




              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") );

              1 person found this helpful
              • 4. Re: Cleaning up the stage
                saratogacoach Newcomer



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



                • 5. Re: Cleaning up the stage
                  sinious Ninja

                  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.

                  1 person found this helpful
                  • 6. Re: Cleaning up the stage
                    saratogacoach Newcomer

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