我有Timer
,当时间到期时,它会转到另一个场景。移动鼠标时,Timer
会重置。但是,当时间到期(并且它进入另一个场景)并且我回到第一个场景(通过点击另一个场景的舞台上)时,我的计时器鼠标事件不再起作用。时间不会重置,而是时间到期并再次转到另一个场景。我在我的MOUSE_MOVE
事件方法中添加了一条跟踪,所以我看到那里发生了什么,时间没有被重置。有人可以帮忙吗?
这是我的代码:
//Define, Set and Start Timer
var myTimer:Timer;
myTimer = new Timer(10000, 1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
myTimer.start();
//Mouse Move Events, Reset Timer when you move the mouse
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoved);
stage.addEventListener(TouchEvent.TOUCH_BEGIN, mouseMoved);
//Timer Complete Method
function onTimerComplete(event : TimerEvent) : void
{
gotoAndStop(1, "Screensaver");
}
//Time Mouse Move Method, Reset Timer when you move the mouse
function mouseMoved(event:MouseEvent):void
{
myTimer.stop();
myTimer.reset();
myTimer.start();
}
以下是我的屏幕保护程序场景中的点击事件:
stage.addEventListener(MouseEvent.CLICK, stopScreensaver);
function stopScreensaver(e:MouseEvent):void
{
screensaver1.visible = false;
screensaver2.visible = false;
screensaver3.visible = false;
screensaver4.visible = false;
screensaver5.visible = false;
screensaver6.visible = false;
screensaver7.visible = false;
screensaver8.visible = false;
touchStart.visible = false;
timer.stop();
timer.reset();
stage.removeEventListener(MouseEvent.CLICK, stopScreensaver);
timer.removeEventListener(TimerEvent.TIMER,timerListener);
stage.removeChild(whiteBackground);
gotoAndStop(1, "Home");
}