3 Replies Latest reply on Jul 12, 2018 7:59 PM by ClayUUID

    Javascript HTML5 removeEventListener of button fails

    jekaterina2 Level 1

      I have three cases that either addEventListener to five buttons or addEventListener to certain buttons or removeEventListener from all buttons. However, I failed to removeEventListener from the buttons. What's wrong with my code? Please help, thanks!

       

       

       

      var set = true;
      
      
      var showFeedback1 = showFeedback.bind(this, 0);
      var showFeedback2 = showFeedback.bind(this, 1);
      var showFeedback3 = showFeedback.bind(this, 2);
      var showFeedback4 = showFeedback.bind(this, 3);
      var showFeedback5 = showFeedback.bind(this, 4);
      
      stage.addEventListener("tick", checkShowFeedback.bind(this))
      
      function checkShowFeedback() {
      
      // s2 currentRound 1 4 7
      
      if (set) {
      
      if (currentRound % 3 == 1) {
      
      console.log("currentRound % 3 == 1");
      
      for (var i = 0; i < 5; i++) {
      
      if (tempS[i] < 60) {
      
      console.log("temps ", i);
      this.scoreSheet_label.gotoAndStop(0);
      this.scoreSheet_label.visible = true;
      
      switch(i){
      case 0:
      this.feedbackCategory1.addEventListener("click", showFeedback1);
      break;
      
      case 1:
      this.feedbackCategory2.addEventListener("click", showFeedback2);
      break;
      
      case 2:
      this.feedbackCategory3.addEventListener("click", showFeedback3);
      break;
      
      case 3:
      this.feedbackCategory4.addEventListener("click", showFeedback4);
      break;
      
      case 4:
      this.feedbackCategory5.addEventListener("click", showFeedback5);
      break;
      
      }
      
      }
      
      
      }
      }
      
      
      // s3 currentRound 2 5 8 9
      
      else if (currentRound % 3 == 2 || currentRound == 9) {
      
      console.log("currentRound % 3 == 2 || currentRound == 9");
      this.scoreSheet_label.gotoAndStop(1);
      this.scoreSheet_label.visible = true;
      
      this.feedbackCategory1.addEventListener("click", showFeedback1);
      this.feedbackCategory2.addEventListener("click", showFeedback2);
      this.feedbackCategory3.addEventListener("click", showFeedback3);
      this.feedbackCategory4.addEventListener("click", showFeedback4);
      this.feedbackCategory5.addEventListener("click", showFeedback5);
      } 
      
      else {
      console.log("else");
      this.scoreSheet_label.visible = false;
      this.feedbackCategory1.removeEventListener("click", showFeedback1);
      this.feedbackCategory2.removeEventListener("click", showFeedback2);
      this.feedbackCategory3.removeEventListener("click", showFeedback3);
      this.feedbackCategory4.removeEventListener("click", showFeedback4);
      this.feedbackCategory5.removeEventListener("click", showFeedback5);
      }
      
      
      set = false;
      
      
      }
      
      
      }
      
      
      
      
      
      
      
      
      
      
      function showFeedback(i) {
      category = i;
      this.left_arrow_scoreSheet.visible = false;
      clearGraph();
      this.feedback.visible = true;
      triggerShowFeedbackSentence = true;
      }