0

I am working on a HTML5 web quiz game in Adobe Animate and I am having trouble removing a bound click event listener. Any help would be much appreciated.

Here is how I add the event listener:

 this.choiceA.addEventListener("click", this.f_choiceA.bind(this));

Here is the function that runs and attempts to remove the event listener. It stays in place and activates the function with every click on the choiceA object.

 this.f_choiceA = function() 
 {
    this.choiceA.removeEventListener("click", this.f_choiceA.bind(this));   
    this.choiceA.play();
    if (answer == "A"){
        this.correctAnswer();
        }
    else {
        this.wrongAnswer();
    }
 }
  • `.bind` creates a _new_ function, so the references won’t be the same. – Sebastian Simon Nov 13 '17 at 21:12
  • Thank you. You gave me the lead I needed to figure this out. – ReviewEcon Nov 13 '17 at 22:21
  • For the record... I could not find a solution to my question on stackoverflow. I did search beforehand. Other similar questions did not provide a solution. Here was my solution: var _this = this; _this.choiceA.removeEventListener("click", f_choiceA); – ReviewEcon Nov 13 '17 at 22:23

0 Answers0