您好我正试图在MainMenu类的秒表课程中停止计时器。但我的代码不起作用,这是我的代码:
在MainMenu班我的方法:
public function pauseGame (e:MouseEvent){
timestop = new Stopwatch();
timestop.Stoptimer();
}
在秒表课程中我尝试用以下方法停止我的计时器:
public function Stoptimer(){
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, timeFun);
return;
}
答案 0 :(得分:1)
没有看到更多代码我只能猜测,但我认为问题是你在暂停游戏时创建一个新的秒表
public function pauseGame (e:MouseEvent){
timestop = new Stopwatch(); // <-- a new instance with a new timer inside
timestop.Stoptimer();
}
timestop应该是一个全局变量,所以你不需要再次实例化它,所以这应该足够了:
public function pauseGame (e:MouseEvent){
timestop.Stoptimer();
}