Reputation: 7243
How do I remove all children of a movieclip?
I tried
while(radar.numChildren > 0){
radar.removeChildAt(0);
}
but this causes the movieclip graphic itself to be removed.
Upvotes: 1
Views: 10587
Reputation: 86
I wrote this class a while back. It creates a bitmap snapshot of the contents of a MovieClip. Removes all the children, then adds the Bitmap to the container. The original intent of this class/classes was to give you a smooth render of images rescaled. In Flash, if you have an image in a MovieClip and you scale it down, the Bitmap can lose its crispness. Using the "smoothing" property of the BitmapData class (automatically set) the integrity is preserved.
You simply extend the class in the Library instance, with the class that works with what you need.
Framework (in progress) - https://github.com/charlesclements/as3-tools
Classes directory to reference - https://github.com/charlesclements/as3-tools/tree/master/net/charlesclements/gadgets/display
SimpleAutoSmoothMovieClip.as - This is the easiest one to use. The class assumes all content to be captured is within the (x:0,y:0) registration point. From there the width is automatically calculated.
AutoSmoothMovieClip.as - This class expects there to be a child MovieClip with an instance name "gr" containing all of the content to take a snapshot of. this "gr" MovieClip will get removed dynamically.
Upvotes: 0
Reputation: 3907
If you only want to remove the Movieclips in your main movieclip (radar) without removing the shapes (graphics) you could do this:
for (var i : int = radar.numChildren-1 ; i >= 0 ; i--)
{
if(radar.getChildAt(i) is MovieClip)
{
radar.removeChildAt(i);
}
}
Upvotes: 2
Reputation: 5581
but this causes the movieclip graphic itself to be removed.
You are removing all of it's child DisplayObjects
. You cannot remove all of the child objects and not lose "the grapics".
Upvotes: 1