Flash中一段时间不活动后的navigateToURL
如果鼠标在三分钟内没有移动,我希望重新启动我的应用程序。我使用“navigateToURL”返回第一个场景,但是如何使用actionscript 3实现这样一个定时事件?非常简单-您需要使用两个事件侦听器:Flash中一段时间不活动后的navigateToURL,flash,Flash,如果鼠标在三分钟内没有移动,我希望重新启动我的应用程序。我使用“navigateToURL”返回第一个场景,但是如何使用actionscript 3实现这样一个定时事件?非常简单-您需要使用两个事件侦听器: MouseEvent.MOUSE\u移动事件侦听器 TimerEvent.TIMER事件侦听器 您还需要一个计时器对象 这是代码 //private timer var in your class private var myLittleTimer:Timer; /
//private timer var in your class
private var myLittleTimer:Timer;
//This is your main function, where you adding all the event listeners
//IMPORTANT NOTE:
//We can only track mouse movement over the flash stage in a DisplayObject that
//has the link to the main stage
//For example, your main SPRITE
yourMainFunction():void{
//Timer initialization
this.myLittleTimer = new Timer(3000, 1);
this.myLittleTimer.addEventListener(TimerEvent.TIMER, lazinessDetector);
this.myLittleTimer.start();
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void{
this.removeEventListener(Event.ADDED_TO_STAGE, init);
//THIS IS THE ENTRANCE POINT
//do not use stage object before the sprite has been added to the stage
//as it will cause a null object exception
//We add a MOUSE_MOVE event listener to the stage to track the moment when
//the mouse has moved
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseMove(e:MouseEvent):void{
this.myLittleTimer.reset();
this.myLittleTimer.start();
//This function will reset the "countdown" timer and start it over again.
}
private function lazinessDetector(e:TimerEvent):void {
//YOUR URL REDIRECT CODE GOES HERE
}