开发者

Make a movieclip remove all of it's children

How do I remove all children of a movieclip?

I tried

while(radar.numChildr开发者_如何学编程en > 0){
    radar.removeChildAt(0);
}

but this causes the movieclip graphic itself to be removed.


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


function removeChildrenOf(mc:MovieClip):void{
    if(my_mc.numChildren!=0){
        var k:int = mc.numChildren;
        while( k -- )
        {
            mc.removeChildAt( k );
        }
    }
}

reference


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".


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜