LISTENERS: Defining MouseUp functions for multiple MCs

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

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:

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

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

pom :asian:

Yes, you’re right ! Thanks :slight_smile: 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.

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:

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

Regards,
Spongebob