Skip to main content
chenjil43641795
Brainiac
September 8, 2018
Answered

ANCC HTML5 .How to make a click event execute only 1 times

  • September 8, 2018
  • 1 reply
  • 1352 views

I use the code below to manipulate.

Use gotoAndStop to jump to this frame,

will be again "var kg = True"

Causes the button to click again.

Is there any other way to make the button perform only 1 times?

var kg = true

this.on("click", pd);
function pd()
{

if(kg)
{
  this.play();
  kg = false
}

}
this.stop();

    This topic has been closed for replies.
    Correct answer kglad

    use:

    if(!this.alreadyExecuted){

    this.alreadyExecuted=true;

    var pdF=pd.bind(this);

    this.addEventListener('click',pdF);

    }

    function pd(){

    this.removeEventListener('click',pdF);

    this.play();

    }

    1 reply

    kglad
    Community Expert
    September 8, 2018

    among the ways to do this:

    var alreadyExecuted;

    if(!alreadyExecuted){

    alreadyExecuted=true;

    var pdF=pd.bind(this);

    this.addEventListener('click',pdF);

    }

    function pd(){

    this.removeEventListener('click',pdF);

    this.play();

    }

    chenjil43641795
    Brainiac
    September 8, 2018

    The code is still invalid,

    When the movie loops and then jumps to the start, the button can be executed again, unable to implement 1 times.

    Brainiac
    September 8, 2018

    Just use on with the "once" flag set.

    https://createjs.com/docs/easeljs/classes/EventDispatcher.html#method_on

    this.on("click", this.play, this, true);

    And DON'T let your movie loop to the start.