Skip to main content
AlexPromTrad
Inspiring
May 19, 2020
Answered

Multiple listeners

  • May 19, 2020
  • 2 replies
  • 1470 views

Hello, I have finally managed to create my event listeners for both mouse hover and tap, and a mouse out.

I have 16 elements that I need to enable animations for.

Each element has its own movie clip and dedicated button and a corresponding instance.

If I add another element to the code, I don't get the desired result as only the first button enables the last element programmed.

I don't understand why because all the instance names are correct and the code also has all the instances replaced in the code.

Is there something that I don't know and I should know when having multiple event listeners?

So far I have copied and pasted the same code replacing the instance names (and adding all the animation in the involved movie clips, with relative stops.

Plase, find the code below.

Thanks in advance 🙂

//BELLY
this.bellyBT.addEventListener("click", MouseClickFunction.bind(this));

function MouseClickFunction() {
	this.bellyMC.play();
}
var frequency = 3;
stage.enableMouseOver(frequency);

this.bellyBT.addEventListener("mouseover", MouseOverFunction.bind(this));

function MouseOverFunction() {
	this.bellyMC.play();
}
this.bellyBT.addEventListener("mouseout", MouseOutFunction.bind(this));

function MouseOutFunction() {
	this.bellyMC.gotoAndPlay(6);
}
    This topic has been closed for replies.
    Correct answer ClayUUID

    You can edit your posts, you know.

     

    I didn't ask about the names of your buttons and movieclips, I asked about the names of your event handler functions. What are you calling them instead of "MouseClickFunction", etc. over and over?

    2 replies

    AlexPromTrad
    Inspiring
    May 20, 2020

    You saved me!! I was looking in the completely wrong direction!

    Yes, the function names!!

    Sorry, I just realized I could edit my post.

    Many thanks!

    Legend
    May 19, 2020

    I assume you haven't done something silly like creating 16 sets of event handler functions with the exact same names.

    AlexPromTrad
    Inspiring
    May 19, 2020

    No, every instance has its own name and I haven't created more functions, because when I create the second group of event listeners and I give them the correct names, it only affects the first... so basically, what I want to happen with the second button, happens with the first button on the second animation.