Flex / AS3 – Remove all children of a container

I know this is not that big thing. But still wanna scribble it down. In order to remove all the children of the container, there is no set function available. You can write a generic method, may be a static method and call that. The logic is to iterate over all the available children and remove one by one. Something like this :

static public function removeAllChildren(parent:UIComponent):void{
while(parent.numChildren > 0 ){
parent.removeChildAt( 0 );

The parent can be either UIComponent or its subclass. The best practice would be to write this method in your component itself, so that this method will become a part of the component. Then you can write something like this :

public function removeAllChildren():void{
while(numChildren > 0 ){
removeChildAt( 0 );

That’s all guys, Happy Coding. 🙂


Tags: , , , , ,

One Response to “Flex / AS3 – Remove all children of a container”

  1. Tyee Cambron Says:

    This is making me crazy haha. I can’t get removeChildren to work and this didn’t work either. The removeChild(0) does work in my 2nd if statement but not in my 1st if statement. My 1st if statement is running code. I have a function call before the removeChildren and its acting like a BASIC GOTO with no return or something like that. I take a good break now and get at this later…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: