很難分辨出問題所在,因爲您確實沒有發佈足夠的代碼。確保你的方法看起來像這樣。此代碼已經過測試並可正常工作
package{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
public class Test extends Sprite{
private var txt:TextField;
private var score:uint = 0;
public function Test()
{
//creating my text field
txt = new TextField();
addChild(txt);
//drawing a black rectangle to use as a "button"
var spt:Sprite = new Sprite();
spt.graphics.beginFill(0x000000);
spt.graphics.drawRect(0, 0, 50, 50);
spt.graphics.endFill();
addChild(spt);
spt.y = 50;
//adding the click event to the "button"
spt.addEventListener(MouseEvent.CLICK, handleClick);
}
protected function handleClick(event:MouseEvent):void
{
//adding 10 to score
score += 10;
//setting the txt text field to score
txt.text = score.toString();
}
}
}
您需要顯示其餘代碼,包括按鈕事件回調。 – 2012-03-28 19:00:20
//事件收聽者 var score:uint; 函數updateScore():void { \t score + = 10; scoreCounter.text = score.toString();函數stonePoint(e:MouseEvent):void { if(MouseEvent.MOUSE_DOWN){ updateScore(); scoreCounter.text = score.toString(); }} // 功能 hatPoint(E:MouseEvent)方法:無效{ 如果(的MouseEvent.MOUSE_DOWN){ updateScore(); scoreCounter.text = score.toString(); } } – 2012-03-28 19:16:01
對不起,我不能回答我自己的問題,我需要至少100個聲望或等待8小時 – 2012-03-28 19:17:29