/ Published in: ActionScript 3
Expand |
Embed | Plain Text
private function deleteChildrenInMovieClip(_movieClip:Sprite):void { if (_movieClip.numChildren>0) { for (var i:uint = 0; i < _movieClip.numChildren; i++) { _movieClip.removeChildAt(i); } } }
Comments
Subscribe to comments
You need to login to post a comment.

I've not tested this code but I'm pretty sure it won't work in its current state. When you remove a child then the childIndex of all the siblings are reordered. So what was previously at childIndex 2 will become 1 and so on.
The correct way to do this is to change _movieClip.removeChildAt(i); to _movieClip.removeChildAt(0); - you will still walk through the children and remove all of them but without throwing any errors.
^what he said
xerode said true, other we can use
while(_movieClip.numChildren>0) { _movieClip.removeChildAt(0); }
=> http://snipplr.com/view/41655/delete-all-childs/ work fine