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

Multiple listeners

Explorer ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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);
}

Views

1.1K

Translate

Translate

Report

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?

Votes

Translate

Translate
LEGEND ,
May 19, 2020 May 19, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

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