2013-02-22 96 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设置在别的地方?

相关问题