Skip to main content
Participating Frequently
November 1, 2021
Answered

removeEventListener(

  • November 1, 2021
  • 2 replies
  • 400 views
I'm developing a program that rotates when I put the mouse on the gogogo button and stops when I click the mouse

The rotation was successful, but the stop failed

I want to know how to modify it

/////////// animate cc (canvas)
//////////////////////////////////////////////////////////////////////////////////////////////
this.stop();
/////////////////////////////////////////////////////
var gunx = this.gun.x;
var guny = this.gun.y;
/////////////////////////////////////////////////////
var cx = this.cen.x;
var cy = this.cen.y;
var a = 80;
var b = 80; //초기쎄타각도 잡기
/////////////////////////////////////////////////////
 
////////////////////////////////////////////////////
var tgun = 3.14;
function gun_fnc() {
this.gun.x = cx + a * Math.cos(tgun);
this.gun.y = cy + b * Math.sin(tgun);
tgun = tgun + 0.8;
}
/////////////////////////////////////////////////////////////////////////////////
//                            mouseover    
/////////////////////////////////////////////////////////////////////////////////
var frequency = 3;
stage.enableMouseOver(frequency);
this.gogogo.addEventListener("mouseover", fl_MouseOverHandler_3.bind(this));
function fl_MouseOverHandler_3() {
                         this.gun.addEventListener("tick", gun_fnc.bind(this));
}
/////////////////////////////////////////////////////////////////////////////////
//                           click  
/////////////////////////////////////////////////////////////////////////////////
this.gogogo.addEventListener("click", gogogo_MouseClickHandler.bind(this));
function gogogo_MouseClickHandler() {
 
              this.gun.removeEventListener("tick", gun_fnc);  //   fail (1)
              this.gun.removeEventListener("tick", gun_fnc.bind(this));  //   fail (2)
              this.gun.x = gunx;
              this.gun.y = guny;
}

 

    This topic has been closed for replies.
    Correct answer kglad

    try:

     

    //                            mouseover    
    /////////////////////////////////////////////////////////////////////////////////
    var frequency = 3;
    stage.enableMouseOver(frequency);
    this.gogogo.addEventListener("mouseover", fl_MouseOverHandler_3.bind(this));
    function fl_MouseOverHandler_3() {
    this.f = gun_fnc.bind(this);
                             this.gun.addEventListener("tick", this.f);
    }
    /////////////////////////////////////////////////////////////////////////////////
    //                           click  
    /////////////////////////////////////////////////////////////////////////////////
    this.gogogo.addEventListener("click", gogogo_MouseClickHandler.bind(this));
    function gogogo_MouseClickHandler() {
     
                  this.gun.removeEventListener("tick", this.f); 
                  this.gun.x = gunx;
                  this.gun.y = guny;
    }
     
    p.s. that's a mess but it looks like you might need to remove the mouseover listener too or you may get multiple mouseover listener function calls.

    2 replies

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    November 1, 2021

    try:

     

    //                            mouseover    
    /////////////////////////////////////////////////////////////////////////////////
    var frequency = 3;
    stage.enableMouseOver(frequency);
    this.gogogo.addEventListener("mouseover", fl_MouseOverHandler_3.bind(this));
    function fl_MouseOverHandler_3() {
    this.f = gun_fnc.bind(this);
                             this.gun.addEventListener("tick", this.f);
    }
    /////////////////////////////////////////////////////////////////////////////////
    //                           click  
    /////////////////////////////////////////////////////////////////////////////////
    this.gogogo.addEventListener("click", gogogo_MouseClickHandler.bind(this));
    function gogogo_MouseClickHandler() {
     
                  this.gun.removeEventListener("tick", this.f); 
                  this.gun.x = gunx;
                  this.gun.y = guny;
    }
     
    p.s. that's a mess but it looks like you might need to remove the mouseover listener too or you may get multiple mouseover listener function calls.
    Participating Frequently
    November 2, 2021

    I know how to use it (removeEventListener) ... Thank you!

    kglad
    Community Expert
    Community Expert
    November 2, 2021

    you're welcome 

    LinSims
    Community Expert
    Community Expert
    November 1, 2021

    Please let us know which program you are having problems with. Someone will be along to move this post to the appropriate product forum, where you are more likely to get an answer to your question.

    The Using the Community forum is for help in using the Adobe Support Community forums, not for help with specific programs. Product questions should be posted in the associated product community.