Need help removing a bunch of objects added at runtime via a timer
Hi. After adding an image to the stage, turning it into a Movie clip, and setting linkage in library to Export for Actionscript, I'm now using a timer to add a bunch of roses to the stage as a video plays.
How can I get rid of all these clips once the video is over?
Do I need to add all of them into an extra container and then just removeChild that container at the end?
Or do I need to use something like getNumberOfChildren and then create a loop that removes them one by one?
The clips (myRose) are fairly small and do not have any event listeners added to them. I just use TweenMax to move them from top to bottom of the screen.
I've pasted my code below.
Thanks for any suggestions.
public function roseTimer():void
{
MonsterDebugger.trace(this, "in roseTimer");
myRoseTimer = new Timer(1200, 52);
myRoseTimer.addEventListener(TimerEvent.TIMER, createRose);
myRoseTimer.start();
}
private function createRose(event:TimerEvent):void
{
MonsterDebugger.trace(this, "test create rose see if stop blinking one");
MonsterDebugger.trace(this, "in createRose");
var myRose:rose = new rose();
var startX:int = (stage.stageWidth/8) + (Math.round (Math.random() * (stage.stageWidth*.75) ) );
var makeSubtract:int;
//Math.random()>.5 ? makeSubtract = 1 : makeSubtract = -1; //shorthand if statement
var endX:int = startX + Math.random()*100*makeSubtract;
if (endX<100)
{
endX +=100;
}
if (endX> stage.stageWidth -100)
{
endX -=100;
}
//MonsterDebugger.trace(this, "makeSubtract = " + makeSubtract + " and startX = " + startX + " and endX = " + endX + " and stage.stageWidth = " + stage.stageWidth);
//var myScale:Number = 1 + (Math.random()*.3*makeSubtract);
var startY:int = Math.round(Math.random()*100);
var endY:int = stage.stageHeight - Math.round(Math.random()*175);
var startRotation = Math.random()*360;
var endRotation = Math.random()*360;
myRose.x = startX;
myRose.y = startY - 150;
//TweenMax.fromTo(myRose, 5, {scaleX: myScale, scaleY: myScale, x:startX, y:startY, alpha: .4, rotationZ:endRotation}, {scaleX: myScale, scaleY: myScale, x:endX, y:endY, alpha:.9, rotationZ:endRotation});
TweenMax.fromTo(myRose, 5, {x:startX, y:startY, alpha: 0, rotationZ:startRotation}, {x:endX, y:endY-75, alpha:.9, rotationZ:endRotation});
//myRose.visible = true;
//Gaia.api.getDepthContainer(Gaia.TOP).addChild(myRose);
addChild(myRose);
}