# LISTENERS: Defining MouseUp functions for multiple MCs

**URL:** <https://forum.kirupa.com/t/listeners-defining-mouseup-functions-for-multiple-mcs/1105>\
**Category:** flash\
**Created:** [August 8, 2002, 4:38pm UTC](https://forum.kirupa.com/t/listeners-defining-mouseup-functions-for-multiple-mcs/1105 "2002-08-08T16:38:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spongebob](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@Spongebob](https://forum.kirupa.com/u/Spongebob)\
**Post date:** [August 8, 2002, 4:38pm UTC](https://forum.kirupa.com/t/listeners-defining-mouseup-functions-for-multiple-mcs/1105/1 "2002-08-08T16:38:59Z")

</div>

Hi there,  
I’m trying to use Listeners to capture the MouseUp event based on Helen Triolo’s sample at [http://www.actionscript-toolbox.com/samplemxlisteners.php](http://www.actionscript-toolbox.com/samplemxlisteners.php)  
I reused her code and loaded the listener’s array (with MC names that will listen to the MU event) from a textfile.

```
My problem is that I don’t have these MCs on the _root. They’re located deep in the MC hierarchy, this way:

```

MCComponent–\>MC1–\>MC2–\>[COLOR=orangered]MCs I want to address for listening [/COLOR]

(I have about 250 MCs in this level of depth which I want to to address for listening)

```
So, when defining the MouseUp function for each MC to respond to, I couldn’t address the MCs. I tried in different ways without any result.

```

This is the code:  
// set up responders for each listener  
// listeners is the Array with MC names which I loaded from  
// the textfile

[COLOR=deeppink]for (var i in listeners) {[/COLOR]

trace(this[listeners\*]); // —\> Undefined because “this” is the root level and my MCs are not there

[COLOR=blue]this[listeners\*].onMouseUp = function() {[/COLOR]  
[COLOR=sienna]trace(“I’m in :)”);[/COLOR]  
[COLOR=blue]};[/COLOR]  
[COLOR=green]Mouse.addListener(this[listeners\*]);[/COLOR]  
[COLOR=deeppink]}[/COLOR]

Is there any way of making this work? Is there something missing in this code ?  
Note: I cannot put these MCs on the root because of other functionalities that they need to accomplish…

By the way…, what about RollOver and RollOut ? Can they be captured too ? I’ve read about capturing MouseUp, Move and Down but not Rollovers… Can it be done in a “custom” way ? Could you tell me where to read about this ?

Thanks in advance,  
Spongebob

---

<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:** [August 8, 2002, 5:12pm UTC](https://forum.kirupa.com/t/listeners-defining-mouseup-functions-for-multiple-mcs/1105/2 "2002-08-08T17:12:53Z")

</div>

Arghh! Tough question. I don’t know the answer, but I think that if your object is a movie clip, it is automatically a listener, so you don’t have to register it. But that path thing, I don’t know. Can’t you put the code inside your mc?

pom :asian:

---

<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:** [August 8, 2002, 5:48pm UTC](https://forum.kirupa.com/t/listeners-defining-mouseup-functions-for-multiple-mcs/1105/3 "2002-08-08T17:48:10Z")

</div>

I’m trying not to put the code inside the MC (that’s how it’s working now) cause I have 250 to do with. I don’t mind pasting the code for each MC, but I DO MIND if I have to add a new parameter to the function I’m calling… (I think there’s no global Search/Replace of code in Flash…) I should do for every MC…

But the main problem is: what if I decide to change all of the MCs for another ones ? (I`ll probably have to do this for other projects…). I don’t want to paste the code to every MC each time I use this in another project…

Regards,  
Spongebob

---

<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:** [August 8, 2002, 6:58pm UTC](https://forum.kirupa.com/t/listeners-defining-mouseup-functions-for-multiple-mcs/1105/4 "2002-08-08T18:58:21Z")

</div>

No, I meant in the MC2 timeline. You could put your loop there, no? Then the this would be the right this.

pom :asian:

---

<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:** [August 8, 2002, 8:03pm UTC](https://forum.kirupa.com/t/listeners-defining-mouseup-functions-for-multiple-mcs/1105/5 "2002-08-08T20:03:38Z")

</div>

Yes, you’re right ! Thanks 🙂 It’s working fine.

Now… is there a way of detecting which of my MCs triggered the mouse click ? Like you can do in Javascript with event.srcElement (IE) ? When I click anywhere on the stage actions within the onMouseUp function perform for every MovieClip !

I thought that if I defined onMouseUp functions for each (in the dynamic way I did), the corresponding one would be performed when I clicked on the MC. As I understand, defining onMouseUp functions the way I did is like having done:

MC1.onMouseUp = function() {  
xxxxx  
}  
MC2.onMouseUp = function() {  
xxxxx  
}

… and so on for each MC.

Thought that it worked that way…, but each of these functions execute everytime I click on the stage (anywhere). If I click on MC130 I want only that function to perform!

Am I wrong ?  
Is there a way of solving this ?

Thanks in advance,  
Sandra.

---

<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:** [August 8, 2002, 8:29pm UTC](https://forum.kirupa.com/t/listeners-defining-mouseup-functions-for-multiple-mcs/1105/6 "2002-08-08T20:29:10Z")

</div>

Of course, there’s a way!

As a matter of fact, rather than setting an onMouseUp callback function, just replace it with onRelease. onMouseUp does its job all right: it broadcasts a message whenever the mouse is ‘unclicked’, whatever its position. But onPress makes your clip behave like a button.

Glad that you could make that work!

pom :asian:

---

<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:** [August 8, 2002, 8:59pm UTC](https://forum.kirupa.com/t/listeners-defining-mouseup-functions-for-multiple-mcs/1105/7 "2002-08-08T20:59:44Z")

</div>

You’re the Master! =) It worked perfectly!  
Millions of thanks for taking the time to answer.

Regards,  
Spongebob
