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.

    avid_body16B8
    Brainiac
    September 9, 2018

    If you jump to this frame again.

    Active will be equal to 1 again.

    It caused the failure.

    If you write to the global function directly then there is no problem.( active = 1;Do not use Var)

    I want to know the way to not use global functions.


    Then do not go back to the initial frame. I put most of my code on frame 1 and then control everything from there. I have been totally successful controlling plays exactly as I want especially when I want something to happen only once.