# Arg, stupid onClipEvents!

**URL:** <https://forum.kirupa.com/t/arg-stupid-onclipevents/18471>\
**Category:** Uncategorized\
**Created:** [April 17, 2003, 12:56am UTC](https://forum.kirupa.com/t/arg-stupid-onclipevents/18471 "2003-04-17T00:56:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GW02](https://avatars.discourse-cdn.com/v4/letter/g/c0e974/32.png) [@GW02](https://forum.kirupa.com/u/GW02)\
**Post date:** [April 17, 2003, 12:56am UTC](https://forum.kirupa.com/t/arg-stupid-onclipevents/18471/1 "2003-04-17T00:56:08Z")

</div>

I have duplicated a movieclip many times.

How do I seperate the onClipEvents for each one… right now when I click on one, all of them respond. How do I seperate it?

AGH!!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 17, 2003, 1:06am UTC](https://forum.kirupa.com/t/arg-stupid-onclipevents/18471/2 "2003-04-17T01:06:15Z")

</div>

use an if check in the events

onClipEvent(enterFrame){  
if (this.\_name = “origClip”){  
// do the stuff  
}  
}

just make sure not to name the duplicated clips the same name as the original (“origClip” in this example)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 17, 2003, 3:01am UTC](https://forum.kirupa.com/t/arg-stupid-onclipevents/18471/3 "2003-04-17T03:01:42Z")

</div>

Unfortunately, I don’t know exactly which one I’m looking for. Here’s my predicament:

I have a whole bunch of duplicated clips randomly lying on the stage. When one is clicked, I wanna destroy it.

How would I go about that?

I would upload the .fla, but it’s on the other computer…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 17, 2003, 4:19am UTC](https://forum.kirupa.com/t/arg-stupid-onclipevents/18471/4 "2003-04-17T04:19:41Z")

</div>

on(release){  
for(obj in \_root){  
if(\_root[obj].hitTest(\_xmouse,\_ymouse,true){  
\_root[obj].deleteMovieClip();  
}  
}  
}

This method doesn’t need any buttons associated. It uses a hitTest against the object’s outline, vrs the mouse locations.

There might be some tweeking that will need to be done, but a for…in loop is the way to go when you don’t know what exactly you’re looking for.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 17, 2003, 5:36pm UTC](https://forum.kirupa.com/t/arg-stupid-onclipevents/18471/5 "2003-04-17T17:36:52Z")

</div>

Shoot, the code looks like it’s supposed to work, but it’s not figuring out which one to destroy. It senses the release event, but the loop isn’t working, methinks. There was a parenthesis missing that I added and there apparently isn’t a deleteMovieClip so I replaced it with removeMovieClip, but it’s not even going into the if execution at all…

Wait, where am I supposed to put this code?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 17, 2003, 5:42pm UTC](https://forum.kirupa.com/t/arg-stupid-onclipevents/18471/6 "2003-04-17T17:42:45Z")

</div>

Okay, I figure it out… I needed to add \_root. to the \_xmouse and \_ymouse properties:

```auto

on(press) {
	for(obj in _root){
		if( _root[obj].hitTest(_root._xmouse,_root._ymouse,true) ) {
			_root[obj].removeMovieClip();
		}
	}
}

```

Thanks all!
