# How to remove dynamically created movieclips? AS2

**URL:** https://forum.kirupa.com/t/how-to-remove-dynamically-created-movieclips-as2/523295
**Category:** flash
**Created:** [February 5, 2015, 8:35pm UTC](https://forum.kirupa.com/t/how-to-remove-dynamically-created-movieclips-as2/523295 "2015-02-05T20:35:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![trollhead](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@trollhead](https://forum.kirupa.com/u/trollhead)
#### Post date: [February 5, 2015, 8:35pm UTC](https://forum.kirupa.com/t/how-to-remove-dynamically-created-movieclips-as2/523295/1 "2015-02-05T20:35:48Z")

</div>

Hey guys,

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

```javascript
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:

```javascript
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”:

```javascript
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

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [February 5, 2015, 9:29pm UTC](https://forum.kirupa.com/t/how-to-remove-dynamically-created-movieclips-as2/523295/2 "2015-02-05T21:29:07Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![trollhead](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@trollhead](https://forum.kirupa.com/u/trollhead)
#### Post date: [February 5, 2015, 9:47pm UTC](https://forum.kirupa.com/t/how-to-remove-dynamically-created-movieclips-as2/523295/3 "2015-02-05T21:47:28Z")

</div>

> [@senocular](#):
>
> 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

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [February 5, 2015, 11:11pm UTC](https://forum.kirupa.com/t/how-to-remove-dynamically-created-movieclips-as2/523295/4 "2015-02-05T23:11:57Z")

</div>

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