Skip to main content
stel27981916
Participant
January 26, 2019
Answered

Canvas Quiz Score

  • January 26, 2019
  • 1 reply
  • 368 views

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();

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    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

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    January 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