I sometimes use the below code when removing all children from a Sprite or MovieClip in AS3:
while(myContainer.numChildren)
{
myContainer.removeChildAt(0);
}
{
myContainer.removeChildAt(0);
}
Here is the Papervision equivalent for removing children from a DisplayObject3D:
good stuff mr. flashmonkey
22 Dec 2009I have an Abstract class that extend Sprite and contains a public dispose() method. That way you can do something like this:
while(myContainer.numChildren)
{
AbstractDisplay(myContainer.getChildAt(0)).dispose();
myContainer.removeChildAt(0);
}
That way it doesn’t matter what your Class is, or even if it contains an override of the dispose method, as long as somewhere along the inheritance line it extends AbstractDisplay. I also always set useWeakReference to true when adding event listeners.
I got the Abstract class from Shane McCartney.
14 Oct 2009and don’t forget to remove those eventlisteners within myContainer.getChildAt(0->numChildren-1)
and within myContainer.getChildAt(0->numChildren-1).getChildAt(0->numChildren-1) and etc…
surely there’s a better way?
i often make a kill function within any class that kills all event listeners, is optionally called when you want to disable a class, and is automatically called if you remove an instance of the class from the displaylist since it listens for the removed from stage event.
12 Oct 2009Cheers… 🙂
12 Oct 2009while(myContainer.numChildren) myContainer.removeChildAt(0);
cheers for the papervision version…
12 Oct 2009