Highlighted

Canvas Quiz Score

New Here ,
Jan 25, 2019

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

Views

66

Likes

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

Canvas Quiz Score

New Here ,
Jan 25, 2019

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

Views

67

Likes

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
Jan 25, 2019 0
Adobe Community Professional ,
Jan 26, 2019

Copy link to clipboard

Copied

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

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

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
Reply
Loading...
Jan 26, 2019 0