Search code examples
actionscript-3flash

End the program itself when there is no movement Action Script 3


Turn off when the programa is not touched for 5-10 minutes. I am using timer Even when the program is touched, it closes when the time is up How can i solve it?

var myTimer:Timer = new Timer(300000);
myTimer.addEventListener(TimerEvent.TIMER, timerListener, false, 0, true);
function timerListener (e:TimerEvent):void{
fscommand("quit");
}
myTimer.start();

Solution

  • Here is a simple example to study...

    var myTimer:Timer = new Timer(300000);
    
    myTimer.addEventListener(TimerEvent.TIMER, timerListener, false, 0, true);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, reset_Timer); //check for any mouse movement
    
    myTimer.start();
    
    function timerListener (e:TimerEvent) :void
    {
        //# function happens when Timer amount is reached (eg: mouse did not move to reset it)
    
        //choose one below..
    
        //fscommand("quit"); //# close app
    
        //myTimer.stop(); myTimer.start(); //# stop and then restart Timer
    
        //stage.removeEventListener(MouseEvent.MOUSE_MOVE, reset_Timer); //# cancel any further usage of this function
    }
    
    function reset_Timer (e:MouseEvent) :void 
    {
        //# function happens after mouse not moved for total millisecond count of Timer amount
    
        myTimer.reset(); //reset countdown because mouse was moved 
    }