Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 16-05-2009
Member
 
Join Date: Apr 2009
Posts: 65
AS3-How to remove all children from Display Object Container

I have some problem with image uploading in my gallery, some times single image gets replicated 1 or more times which overburdens my database, so i wanted to get rid of this problem, Is there anybody who can help me out in removing duplicates in ActionScript3.0 removeChild works and removeChildAt also works but removeAllChildren it shows an error. i want to remove all the children imageclips that have been duplicated within the container at once ... but using removeAllChildren shows error that -- removeAllChildren is not a function. I am using Flash CS3 removeAllChildren works in Flex but not working in Flash CS 3. Any help wouid be appriciated. Thanks in advance.
Reply With Quote
  #2  
Old 16-05-2009
Member
 
Join Date: Dec 2008
Posts: 161
Re: AS3-How to remove all children from Display Object Container

Here I am giving you a little code through which you can remove all children's but it will removes children's in an opposite order it will removes them from the top same as we keep items at the top of the stack instead of the bottom which may be slightly quicker if you have a lot of child objects that need to be removed.

Code:
var children:Array = new Array();

     trace ('before : '+holder.numChildren);
             while(holder.numChildren)
                {
                  holder.removeChildAt(0);
                }

    var i:int = holder.numChildren;
             while( i -- )
                {
                  holder.removeChildAt( i );
                }

     trace ('after : '+holder.numChildren);

     trace ('after : '+holder.numChildren);

     trace ('-------------------------');
Reply With Quote
  #3  
Old 16-05-2009
Member
 
Join Date: Jan 2006
Posts: 211
Re: AS3-How to remove all children from Display Object Container

Sorry for interruption but i also had the same problem so i tried using the above code, After trying the above code several times it did not work to clear all the clips.

This is because i think the reason will be the numChildren changes every loop. I did not want to try too hard to think about why it did not work for me but willing to find out the actual reason behind it and rewrote the above in a recursive function to make sure all clips are removed. It works every time to get rid of all child child clips.

It always remains in the mind why does not offer a collection Array of the children like in Visual Studio so we could use a for each loop.
Reply With Quote
  #4  
Old 16-05-2009
Member
 
Join Date: Jan 2009
Posts: 99
Re: AS3-How to remove all children from Display Object Container

Something like this would remove all children of a displayObjectContainer.

Code:
while( nameOfContainer.numChildren > 0 )
       nameOfContainer.removeChildAt( 0 );
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "AS3-How to remove all children from Display Object Container"
Thread Thread Starter Forum Replies Last Post
How to remove plug-in container.exe from Mozilla Firefox 5 Anchal Technology & Internet 3 22-06-2011 09:33 PM
Getting HP AIO Device object server register class object failed message on my system Donoho Hardware Peripherals 6 06-06-2011 01:34 AM
Scope of Object or variable in Object oriented Programming Languages Dėfrim Software Development 3 08-01-2011 06:20 AM
How can you remove and insert an object in the array list ? GOOL Software Development 4 03-01-2011 11:29 PM
Remove object from pictures Jokerz Customize Desktop 4 13-12-2008 02:58 PM


All times are GMT +5.5. The time now is 12:59 AM.