Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Multiple listeners

Explorer ,
May 19, 2020 May 19, 2020

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);
}
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 19, 2020 May 19, 2020

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?

Translate
LEGEND ,
May 19, 2020 May 19, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2020 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2020 May 19, 2020

What I do is copy and paste the code above, replace the handlers... the rule is simple, somethingBT and somethingMC, and that happens... This is my first time trying to make a script with Animate, so I am not completely sure if there is a different approach.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2020 May 19, 2020

in case this is important... all the event listeners are in the frame 1 of the 'script' layer.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2020 May 19, 2020

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 20, 2020 May 20, 2020
LATEST

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines