/ Published in: ActionScript 3
                    
                                        
I create this recursive function to remove and null all children inside a display object container.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
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;
}
//usage with a movieclip
removeAllChildren(yourMc);
//usage with your root
removeAllChildren(root);
Comments
 Subscribe to comments
                    Subscribe to comments
                
                