So i wanted to create an Idle timer for my OS application and reached to this ..
Enjoy ..
//stop Time line Whenever its needed …
stop();
//Declare our Vars outside the functions
var X:Number = new Number();
var Y:Number = new Number();
var X2:Number = new Number();
var Y2:Number = new Number();
var timer:Number = 0;
var Idle:Number = 10;
var Idle2:Number = 20;//Mouse Listener…
// Creates listener object, MouseListener.
var MouseTrack:Object = new Object();
// functions for listener object , If User is Not Idle Anymore Execute the Actions
MouseTrack.onMouseMove = function() {
trace(“Mouse Moved”)
timer_txt.text = “user is Not Idel”;
Mouse.removeListener(MouseTrack);
clearInterval(intervalID);
startInterval();}
//Create a Text field and assign its x & y Positions …
this.createTextField(“timer_txt”, this.getNextHighestDepth(), 0, 0, 100, 22);
function updateTimer(){
timer += 1;
trace(timer);
if(timer == Idle) {
getMouse()}else if(timer == Idle2) {
checkMouse();}
}
//get Mouse X & Y Positions for the first 10 Sec
getMouse =function () {
X = _root._xmouse;
Y = _root._ymouse;
trace(X);
trace(Y);
}
//Get the Mouse X & Y Positions for the next 10 sec [ 20 sec total ]
checkMouse = function() {
X2 = _root._xmouse;
Y2 = _root._ymouse;
trace(X2);
trace(Y2);
if (X2 == X && Y2 == Y) {
trace((X2 == X && Y2 == Y));
clearInterval(intervalID);
Mouse.addListener(MouseTrack);
timer_txt.text = ” User is Idle “;}else{
//reset timer
timer =0;
}}
function startInterval() {
timer = 0;
_global.intervalID= setInterval(updateTimer, 1000);
}startInterval();
I modified it a bit in order to work like I wanted it to, the way it was at first didn’t work for me so this is how it goes.
It checks if the mouse if moved if it’s not moved in 15sec (var Idle), it plays from a label in a MC (waves.gotoAndPlay(”idle”))
Else it detect the mouse again and starts counting… all over again.
//Declare our Vars outside the functions
var X:Number = new Number();
var Y:Number = new Number();
var X2:Number = new Number();
var Y2:Number = new Number();
var timer:Number = 0;
var Idle:Number = 15;
//Mouse Listener…
// Creates listener object, MouseListener.
var MouseTrack:Object = new Object();
// functions for listener object , If User is Not Idle Anymore Execute the Actions
MouseTrack.onMouseMove = function() {
waves.gotoAndPlay(1);
trace(“Mouse Moved”)
trace( “user is Not Idle”);
Mouse.removeListener(MouseTrack);
clearInterval(intervalID);
startInterval();
}
function updateTimer(){
timer += 1;
trace(timer);
if(timer == Idle) {
waves.gotoAndPlay(“idle”);
getMouse()
checkMouse();
}
}
//get Mouse X & Y Positions for the first 10 Sec
getMouse =function () {
X = _root._xmouse;
Y = _root._ymouse;
trace(X);
trace(Y);
}
//Get the Mouse X & Y Positions for the next 10 sec [ 20 sec total ]
checkMouse = function() {
X2 = _root._xmouse;
Y2 = _root._ymouse;
trace(X2);
trace(Y2);
if (X2 == X && Y2 == Y) {
trace((X2 == X && Y2 == Y));
clearInterval(intervalID);
Mouse.addListener(MouseTrack);
trace(” *******User is Idle*********”);
}else{
//reset timer
timer =0;
}
}
function startInterval() {
timer = 0;
_global.intervalID= setInterval(updateTimer, 1000);
}
startInterval();
good deal 🙂
its a rubbish character, i think that happened when i migrated from my old blog, you can find the original post @ :
http://zainal.wordpress.com/2006/06/11/idle-timer-with-actionscript/
hi,
just like to ask what does”…” code means?