2013-02-22 119 views
0

我一直在收到此錯誤,但我不知道如何解決此問題,它在另一個類中工作,因此它應該在此處工作, 對? (我把它從該類到這一個),唯一的區別是,這個類擴展「遊戲」和其他類擴展「影片剪輯」AS3#1067將flash.utils.timer類型的值強制轉換爲無關類型函數

1067: Implicit coercion of a value of type flash.utils:Timer to an unrelated type Function. 

public static var timeLeft; 

public function GamePlay() { 
    // Start timer 
    var timeCounter:Timer = new Timer(1000, timeLeft) 
    timeCounter.addEventListener(TimerEvent.TIMER, timeCounter); 
    timeCounter.start(); 
} 

// Handle time counter 
public function timeCounter(e:TimerEvent):void { 
    timeLeft--; 
    trace(timeLeft); 
} 

回答

0

您的功能和Timer都被稱爲timeCounter,所以它認爲你試圖通過Timer作爲一個函數(因此錯誤)。你應該重命名其中的一個,在這裏我已經重命名了這個函數:

public static var timeLeft; 

// Start timer 
var timeCounter:Timer = new Timer(1000, timeLeft) 
timeCounter.addEventListener(TimerEvent.TIMER, timeCountHandler); 
timeCounter.start(); 

// Handle time counter 
public function timeCountHandler(e:TimerEvent):void { 
    timeLeft--; 
    trace(timeLeft); 
} 
+0

我現在看到了,謝謝 – Snakybo 2013-02-22 19:09:13

1

你需要給Timer對象和監聽功能不同的名稱:

public static var timeLeft:int; 

var timer:Timer = new Timer(1000, timeLeft) 
timer.addEventListener(TimerEvent.TIMER, timeCounter); 
timer.start(); 

public function timeCounter(e:TimerEvent):void { 
    timeLeft--; 
    trace(timeLeft); 
} 

我假設timeLeft設置在別的地方?

相關問題