Return to Snippet

Revision: 50436
at August 21, 2011 23:52 by radykal


Initial Code
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);

Initial URL


Initial Description
I create this recursive function to remove and null all children inside a display object container.

Initial Title
Remove and null all children of a display object container

Initial Tags
object

Initial Language
ActionScript 3