On 01.05.10, In Flash, by Edwin
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
Edwin
I'm a Flash Developer who's currently working in Kinetic Singapore. Although my focus is in Flash, I'm interested in advertising as well as art direction and hope to be able to progress to become an interactive art director in the future.
If you enjoyed this article, please consider sharing it!
9 Responses
while(mc.numChildren){
mc.removeChildAt(0);
}
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 );
}
You can do that with a sorter version:
while(mc.numChilren > 0)
mc.removeChildAt(0);
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..
wow, thanks for this everyone.
I bet nothing better than this (it is fastest, less code, robust )
while(mc.numChildren) {
mc.removeChildAt(0)
}
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)
}
Sorry, i think, this code is better, else the container will have one remaining child :
while(mc.numChildren => 0)
{
mc.removeChildAt(mc.numChildren – 1)
}