Skip to main content
alemieux3
Known Participant
March 22, 2021
Answered

Multiple event listeners and bind

  • March 22, 2021
  • 1 reply
  • 987 views

I posted this question on Stack Overflow, but didn't get an answer, so I'm re-posting here as it has to do with Animate and binding event listeners to functions.  

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Just reviewing the code: 

this.c3po.addEventListener("click", choice1.bind(this));
this.r2d2.addEventListener("click", choice2.bind(this));

// Function that moves the timeline. In JS, it starts at 0
function choice1() {
	this.gotoAndStop("bantha");
}

function choice2() {
	this.gotoAndStop("rocks");
}

When clicking on R2, it should go to "rocks", but it goes to "bantha" instead, IF you've already gone to "bantha" and have clicked the Back button. I'm testing in Google Chrome. 


Please have a look.

https://drive.google.com/file/d/1okBEybTKwUY65VEewxHP6Ni0IiYWqJmx/view?usp=sharing

1 reply

JoãoCésar17023019
Community Expert
Community Expert
March 22, 2021

Hi.

 

I tested your code and it seems everything is working fine.

 

Can you provide more details?

 

Regards,

JC

alemieux3
alemieux3Author
Known Participant
March 22, 2021

So, in the timeline, the code is in frame 1. If you click either button, it sends you to either frame 5 or frame 10. There's a back button there that sends you to frame 1. Clicking the function on the second button fires the code of the first button.

JoãoCésar17023019
Community Expert
Community Expert
March 22, 2021

Thanks for the info.

 

I can't still reproduce the issue.

 

Would you mind sharing your FLA?