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,
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.
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") );
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.
North America
Europe, Middle East and Africa
Asia Pacific