フレームが変わると変数が反映されません

New Here ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

例えば、1フレームに

var score = 0;

と変数を設定します。

2フレームにボタンを作成し、

this.btn_seikai_1.addEventListener("click", btn_seikai_1.bind(this));

function btn_seikai_1()
{
score = score+10;
this.score_txt.text = score;
}

として、ボタンをクリックしたら、10プラスされるようにしましたが、うまくいきません。

animateでは、変数はフレームが変わると反映されないのでしょうか。

教えていただけるとありがたいです。

 

Views

75

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
community guidelines
Adobe Community Professional ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

in thml5/canvas, variables prefixed by "var" are local to their frame.  if you want the variable to persist after it's defined, use:

 

this.score = 0;

 

if you do not want that variable reset when re-entering that frame, use:

 

if(!this.alreadyExecuted){

this.alreadyExecuted = true;

this.score = 0;

}

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
community guidelines
New Here ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

丁寧に教えていただき、

ありがとうございました。

うまくいきました。

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
community guidelines
Adobe Community Professional ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

LATEST

you're welcome.

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
community guidelines