• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

HTML5 Javascript Button click triggers multiple times

New Here ,
Jul 12, 2018 Jul 12, 2018

Copy link to clipboard

Copied

There is a button when I click once, it increments the qtitlebuttonNo by one. But now out of no reason, it jumps from 1 to 3. But after 3 are all functioning well. Just don't know why when I click the first time, qtitlebuttonNo++; triggers twice so it increments by two from 1 to 3. What can I do to solve it? Thanks.

game2f2 = this;

game2f2.confirm_btn_qanswer.addEventListener("click", showNext_qanswer.bind(game2f2));

var clickedOnce = false;

function showNext_qanswer(){

if(!clickedOnce){

console.log("game2f2 qtitlebuttonNo",qtitlebuttonNo);

game2f1.gotoAndStop(0);

if(qtitlebuttonNo<15) {

qtitlebuttonNo++;

}

else gameOver = true;

game2f1.qno.gotoAndStop(qtitlebuttonNo);

game2f1.qtitlebutton.gotoAndStop(qnumbers[qtitlebuttonNo]);

clickedOnce = true;

}

}

Views

2.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 12, 2018 Jul 12, 2018

Copy link to clipboard

Copied

If it's triggering multiple times, it's because you're adding the event listener multiple times.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

If my frame will be assessed multiple times, will each time it runs the above the code and then adds the event listener again and again?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

Most likely, yes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2018 Jul 13, 2018

Copy link to clipboard

Copied

LATEST

Then what can I do to prevent it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines