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

Canvas Quiz Score

New Here ,
Jan 25, 2019 Jan 25, 2019

Hi! Im using adobe animate canvas, I made a quiz game, everything works but the problem is the score doesnt reset to 0 everytime the game restarts, any solutions for this? Newbie here

here is the code in actions:

Frame 1:

this.score = 0;

this.stop();

this.playbtn.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));

function fl_ClickToGoToAndStopAtFrame()

{

this.gotoAndStop(1);

}

Frame 2:

this.a1.addEventListener("click", fl_ClickToGoToAndStopAtFrame_2.bind(this));

function fl_ClickToGoToAndStopAtFrame_2()

{

this.gotoAndStop(2);

}

this.a2.addEventListener("click", fl_ClickToGoToAndStopAtFrame_3.bind(this));

function fl_ClickToGoToAndStopAtFrame_3()

{

this.score++;   

this.gotoAndStop(2);

}

Frame 3:

this.b1.addEventListener("click", fl_ClickToGoToAndStopAtFrame_4.bind(this));

function fl_ClickToGoToAndStopAtFrame_4()

{

this.score++;

this.gotoAndStop(3);

}

this.b2.addEventListener("click", fl_ClickToGoToAndStopAtFrame_5.bind(this));

function fl_ClickToGoToAndStopAtFrame_5()

{

this.gotoAndStop(3);

}

Frame 4:

this.c1.addEventListener("click", fl_ClickToGoToAndStopAtFrame_6.bind(this));

function fl_ClickToGoToAndStopAtFrame_6()

{

this.gotoAndStop(4);

}

this.c2.addEventListener("click", fl_ClickToGoToAndStopAtFrame_7.bind(this));

function fl_ClickToGoToAndStopAtFrame_7()

{

this.score++;

this.gotoAndStop(4);

}

Frame 5:

this.d1.addEventListener("click", fl_ClickToGoToAndStopAtFrame_8.bind(this));

function fl_ClickToGoToAndStopAtFrame_8()

{

this.score++;

this.gotoAndStop(5);

}

this.d2.addEventListener("click", fl_ClickToGoToAndStopAtFrame_9.bind(this));

function fl_ClickToGoToAndStopAtFrame_9()

{

this.gotoAndStop(5);

}

Frame 6:

this.again.addEventListener("click", Restart);

function Restart()

{

this.gotoAndStop(0);

}

this.puntos1.text = this.score.toString();

351
Translate
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

correct answers 1 Correct answer

Community Expert , Jan 26, 2019 Jan 26, 2019

Hi.

It's because you're not biding the Restart function in the last frame so the this keyword inside of the function body is not referencing the main timeline as you may be expecting.

It should be this:

this.again.addEventListener("click", Restart.bind(this));

Regards,

JC

Translate
Community Expert ,
Jan 26, 2019 Jan 26, 2019
LATEST

Hi.

It's because you're not biding the Restart function in the last frame so the this keyword inside of the function body is not referencing the main timeline as you may be expecting.

It should be this:

this.again.addEventListener("click", Restart.bind(this));

Regards,

JC

Translate
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