添加分数并显示为 3
adding score and displaying as3
我正在尝试为我的测验设置分数。
目前它的工作原理是当用户单击正确答案(这是一个按钮)时,它会显示到表明答案正确的框架并显示分数。
如果用户回答错误(又是一个按钮),它将转到提示答案错误的框架,并且分数将保持不变。
我的测验按钮代码如下:
第一个正确答案:
//implementation of score
var score;
score = 0;
//adding points to score
score ++;
//setting the txt text field to score
scorecounter.text = score.toString();
//not embedding the font to display the score
scorecounter.embedFonts = false;
每个对应的正确答案:
//adding to score
score ++;
//setting the txt text field to score
scorecounter.text = score.toString();
scorecounter.embedFonts = false;
每个对应的错误答案:
//adding to score
score --;
//setting the txt text field to score
scorecounter.text = score.toString();
scorecounter.embedFonts = false;
我有显示分数的静态文本,旁边是空白的动态文本,称为记分器,我希望分数增加一。
现在发生的事情是,当用户回答第一个答案不正确(或足够不正确)以显示 "NaN"。
测验有五个问题,所以如果用户答错了问题,我希望数字变量下降,但只让它下降到零,并且最高分可能达到五(如果用户全部正确)。
我该怎么做?
干杯!
您正在调用自身内部的函数。 updateScore()
不能在 function updateScore():void{}
内。那应该是有道理的。有关如何烤蛋糕的说明不能包含显示 "bake cake" 的步骤。关于如何去医院的说明不能包括 "get to hospital"。您对 updateScore
的说明包括步骤 updateScore
。因此只能从该函数外部调用函数(即告诉 flash 执行该函数)。
因此,您需要的是让所有代码在 updateScore()
期间在函数内执行您想要的操作,并在用户执行应引起更新的操作时调用它。
function myFunction():void{
//do stuff
}
myFunction(); // this will trigger the function and "do stuff" will occur
对于你的新问题:
这段代码需要在函数之外的脚本顶部。
var score:int = 0;
而不是第一道题答对了才宣告。
我认为您仅在正确答案后才声明变量 score
,因此如果第一个答案错误,则分数为 NaN。
我正在尝试为我的测验设置分数。
目前它的工作原理是当用户单击正确答案(这是一个按钮)时,它会显示到表明答案正确的框架并显示分数。
如果用户回答错误(又是一个按钮),它将转到提示答案错误的框架,并且分数将保持不变。
我的测验按钮代码如下:
第一个正确答案:
//implementation of score
var score;
score = 0;
//adding points to score
score ++;
//setting the txt text field to score
scorecounter.text = score.toString();
//not embedding the font to display the score
scorecounter.embedFonts = false;
每个对应的正确答案:
//adding to score
score ++;
//setting the txt text field to score
scorecounter.text = score.toString();
scorecounter.embedFonts = false;
每个对应的错误答案:
//adding to score
score --;
//setting the txt text field to score
scorecounter.text = score.toString();
scorecounter.embedFonts = false;
我有显示分数的静态文本,旁边是空白的动态文本,称为记分器,我希望分数增加一。
现在发生的事情是,当用户回答第一个答案不正确(或足够不正确)以显示 "NaN"。
测验有五个问题,所以如果用户答错了问题,我希望数字变量下降,但只让它下降到零,并且最高分可能达到五(如果用户全部正确)。
我该怎么做? 干杯!
您正在调用自身内部的函数。 updateScore()
不能在 function updateScore():void{}
内。那应该是有道理的。有关如何烤蛋糕的说明不能包含显示 "bake cake" 的步骤。关于如何去医院的说明不能包括 "get to hospital"。您对 updateScore
的说明包括步骤 updateScore
。因此只能从该函数外部调用函数(即告诉 flash 执行该函数)。
因此,您需要的是让所有代码在 updateScore()
期间在函数内执行您想要的操作,并在用户执行应引起更新的操作时调用它。
function myFunction():void{
//do stuff
}
myFunction(); // this will trigger the function and "do stuff" will occur
对于你的新问题:
这段代码需要在函数之外的脚本顶部。
var score:int = 0;
而不是第一道题答对了才宣告。
我认为您仅在正确答案后才声明变量 score
,因此如果第一个答案错误,则分数为 NaN。