I often ask myself, how it is possible to remove and null all underlying children of a object. So I write a small function, which removes and null all children from a parent object. It also checks, if a child is a DisplayObjectContainer, which could even hold more children.
function removeAllChildren(parentChild:*):void { for(var i:uint = 0; i < parentChild.numChildren;++i) { //check if child is a DisplayObjectContainer, which could hold more children if(parentChild.getChildAt(i) is DisplayObjectContainer) removeAllChildren(DisplayObjectContainer(parentChild.getChildAt(i))); else { //remove and null child of parent var child:DisplayObject = parentChild.getChildAt(i); parentChild.removeChild(child); child = null; } } //remove and null parent parentChild.parent.removeChild(parentChild); parentChild = null; }
Just pass e.g. a MovieClip as paramter and all underlying children will be removed and set to null:
removeAllChildren(yourMc);
You could also do this with your root:
removeAllChildren(root);
Best,
Rafael





