AS3: remove All Children in a DisplayObject

function removeChildrenOf(mc:MovieClip):void{ if(mc_mc.numChildren!=0){ var k:int = mc.numChildren; while( k — ) { mc.removeChildAt( k ); } } } Related PostsActionscript 3.0 Basics: The Moving Ball Master Volume Control in AS3.0 First step into AS3.0

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

Related Posts

Actionscript 3.0 Basics: The Moving Ball Master Volume Control in AS3.0 First step into AS3.0

Related Posts

Popular Posts


9 Responses

01.05.10

while(mc.numChildren){
mc.removeChildAt(0);
}

01.05.10

while(mc.numChildren != 0) mc.removeChildAt(0);

This will do the trick! ;)

try this

public static function removeAllChildren ( target:DisplayObjectContainer ) : void
{
while( target.numChildren )
target.removeChildAt( 0 );
}

01.05.10

You can do that with a sorter version:

while(mc.numChilren > 0)
mc.removeChildAt(0);

01.05.10

This would do it too:
function removeChildrenOf(docTarget:DisplayObjectContainer):void {
while(docTarget.numChildren) {
docTarget.removeChildAt(0)
}
}

I wonder if there is any difference in execution speed..

01.05.10

wow, thanks for this everyone.

01.05.10

I bet nothing better than this (it is fastest, less code, robust )

while(mc.numChildren) {
mc.removeChildAt(0)
}

01.05.10

Hello,

I think that it would be better to do as follows, so that the container does not recalculte its children ‘s index every time a child is removed

while(mc.numChildren)
{
mc.removeChildAt(mc.numChildren – 1)
}

01.05.10

Sorry, i think, this code is better, else the container will have one remaining child :

while(mc.numChildren => 0)
{
mc.removeChildAt(mc.numChildren – 1)
}

Leave Your Response

* Name, Email, Comment are Required

Nuffnang Ad

Advertisement