【发布时间】:2012-03-28 18:21:29
【问题描述】:
我一直在尝试为一个小游戏制作一个分数计数器,其中用户点击舞台上的一个按钮,每次用户按下按钮时分数增加 10,但是我无法让分数显示在动态文本字段。我做错了什么?
var score:uint;
//scoreCounter is the instance name of the dynamic text box
function updateScore():void{
score += 10;
scoreCounter.text = score.toString();
}
【问题讨论】:
-
您需要显示其余代码,包括您的按钮事件回调。
-
//事件监听器 var score:uint;函数 updateScore():void{ 分数 += 10; scoreCounter.text = score.toString(); } function stonePoint(e:MouseEvent):void{ if(MouseEvent.MOUSE_DOWN){ updateScore(); scoreCounter.text = score.toString(); }} // 函数 hatPoint(e:MouseEvent):void{ if(MouseEvent.MOUSE_DOWN){ updateScore(); scoreCounter.text = score.toString(); } }
-
抱歉有点乱,但我无法回答我自己的问题,我需要至少 100 名声望或等待 8 小时
-
您应该能够编辑您的问题,并且可以将其包含在其中...但这可能是一个简单的问题,永远不会将分数设置为 0?您需要初始化您的变量,否则您将添加 10 到谁知道什么。
-
@M.Laing 很好,但在这种情况下,将 .text 设置为 score.toString() 不会使“null”或“undefined”出现在文本字段中吗?