How to remove dynamically created movieclips? AS2

Hey guys,

I have a button that uses this code to rollover between 2 frames:

btn_splash.onRollOver = function()
{
	btn_splash.gotoAndStop(2);
};
btn_splash.onRollOut = function()
{
	btn_splash.gotoAndStop(1);
};

When I rollover the button, confetti is created using code. On the frame there is this code:

var mainJumping = true;//whether or not main is in the air
numConfetti = 20;
for (i=2; i<=numConfetti; i++) {
	confetti1.duplicateMovieClip("confetti"+i, i+100);
}

This code is on the movieclip “confetti1”:

onClipEvent (load) {
	function reset()
	{
		//generate the random color
		R = random(256);
		G = random(256);
		B = random(256);
		colorHexString = R.toString(16) + G.toString(16) + B.toString(16);
		colorHex = parseInt(colorHexString, 16);
		hairColor = new Color(this);
		hairColor.setRGB(colorHex);
		//generates random movemtn onscreen
		xSpeed = random(3) + 1;
		ySpeed = (Math.random() + 1) * random(5) + 1;
		if (ySpeed == 1)
		{
			ySpeed = (Math.random() + 1) * random(5) + 1;
		}
		direction = random(2) + 1;
		//randomly places confetti at the top of the screen
		position = random(125) + 1;


		_x = position;
		_y = 0;

	}
	reset();
}
onClipEvent (enterFrame) {
	//makes the confetti fall
	_y += ySpeed;
	directionChange = random(10) + 1;
	if (directionChange == 1)
	{
		direction = random(2) + 1;
		xSpeed = random(3) + 1;
	}
	if (direction == 1)
	{
		_x += xSpeed;
	}
	if (direction == 2)
	{
		_x -= xSpeed;
	}
	if (_y > 125)
	{
		reset();
	}
	if (_x < 0)
	{
		reset();
	}
	if (_x > 125)
	{
		reset();
	}
}

My question is, when i rollout back to frame 1 how can i remove the confetti, or movieclips? Thanks

I think the easiest thing to do is to have confetti inside another movie clip that just acts as a container for confetti to live in. Then have that movie clip only exist in frame 2. When you go back to frame 1, that movie clip goes away and takes all the confetti with it.

â– â– â– â– â– â– â–  GENIUS MATE. 10/10. IT WORKED. LOVE U SO MUCH

Huh. Looks like we didn’t have a profanity filter set up.

1 Like