Timer not acting as expected
I have an FLA file with several frames. Frame 1 is the "home page". Button take you to frame 2, 3, etc. Those frames have movie clip on them. Each movie clip contains 3-4 frames of content.
I found some AS3 code for a timer that track mouse movement. Each time the mouse is touched the timer resets. The timer is set to return to frame 1 (home page) of the main timeline if the mouse is left untouched for longer than a set amount of time in the code.
This timer seems to work fine for a bit. Then it starts getting going haywire the more its used. Some times I jump to a frame with a movie clip on it and after 1 second it jumps back the home page. The next time I navigate down the timeline it may stay on a frame for a longer period of time.
From reading through the forums I am thinking I am trigerring multiple timers maybe. I am not sure.
At the end of the day I want have the site sit at the home page until I click a button to go to another frame to view other movie clips and their content. Once I am done browsing, I want to be a ble to walk away from it and after a set amount of time I want the timeline to return to frame 1 (home page) so it is ready to use for the next person.
Here is the code I am currently using that I found online and tried to repurpose for this.
//------------------
var nPrevMouseX:Number;
var nPrevMouseY:Number;
var myTimer:Timer = new Timer(180000);
myTimer.addEventListener(TimerEvent.TIMER, fOnTimer, false, 0, true);
myTimer.start();
function fOnTimer(evtTimer:TimerEvent):void {
// If the mouse has not moved
if(mouseX == nPrevMouseX && mouseY == nPrevMouseY){
gotoAndStop(1);
stage.addEventListener(MouseEvent.MOUSE_MOVE, fOnMouseMove, false, 0, true);
myTimer.reset();
}else{
// Capture the mouse's position
nPrevMouseX = mouseX;
nPrevMouseY = mouseY;
}
}
function fOnMouseMove(evtMouseMove:MouseEvent):void {
Mouse.show();
// Restart the timer
myTimer.start();
// Remove the listener
stage.removeEventListener(MouseEvent.MOUSE_MOVE, fOnMouseMove);
}
//----------------
Thank you for any insight you might have. Take Care.