Randy,
Someone posted a similar question awhile back. I decided to write this
IdleTimeout class (as an exercise) to see what I could figure out.
Do some testing before using it with your app.
I would greatly appreciate any feedback that you or any other interested
party cares to provide.
-- Watch the wrap --
[code]
/*
***************************************
* Keith H. Reinfeld *
* *
* [EMAIL PROTECTED] *
***************************************
* Application IdleTimeout.
*Usage:
*Define a function in your FLA to execute the desired actions when the idle
timeout ellapses.
*Include in your function a 'yourObject.killIdleTimeout()' call
*to clear the interval and turn off the listeners.
*Instantiate this class:
*var yourObject:IdleTimeout = new IdleTimeout(hours, minutes, seconds,
yourFunctionNameHere);
*/
import mx.utils.Delegate;
class com.khr.IdleTimeout {
//declare timeout variables
//h = how many hours
private var h:Number;
//m = how many minutes
private var m:Number;
//s = how many seconds
private var s:Number;
//userFunc = Function
private var userFunc:Function;
//set a reasonable minimum for the timeout interval: (integer > 0) *
milliseconds
private var iTODurMin:Number;
//time in milliseconds
private var tmpITOIntDur:Number;
//listener objects
private var keysIdleTimeout:Object = new Object();
private var mouseIdleTimeout:Object = new Object();
//make public for testing in trace output
private var iTOIntID:Number;
private var iTOIntDur:Number;
private var intFuncRef:String;
private var clsRef:Object;
//Constructor
public function IdleTimeout(hours:Number, minutes:Number,
seconds:Number, funcRef:Function) {
//init values
h = hours;
m = minutes;
s = seconds;
//validate the user function reference
try {
if (funcRef != undefined) {
userFunc = funcRef;
} else {
throw new Error("The fourth arguement - user
function - is "+funcRef+".");
}
} catch (clsError:Error) {
trace("***Error: "+clsError+"***");
}
tmpITOIntDur = (h*3600000)+(m*60000)+(s*1000);
iTODurMin = (60*1000);
//validate the interval duration variable
try {
if ((!isNaN(tmpITOIntDur)) && (tmpITOIntDur>0)) {
iTOIntDur = tmpITOIntDur;
} else {
throw new Error("Invalid interval duration:
is NaN or less than zero.");
}
} catch (clsError:Error) {
trace("***Error: "+clsError+"***");
trace("***The interval duration will be set to the
default minimun: "+String(iTODurMin)+"***");
iTOIntDur = iTODurMin;
}
intFuncRef = "onIdleTimeoutEllapsed";
clsRef = this;
startTimeout();
createListeners();
}
//Timeout function
private function onIdleTimeoutEllapsed() {
trace("onIdleTimeoutEllapsed called");
//reset app procedure goes here
userFunc();
}
private function startTimeout() {
trace("startTimeout called");
clearInterval(iTOIntID);
iTOIntID = setInterval(clsRef, intFuncRef, iTOIntDur);
}
private function createListeners() {
trace("createListeners called");
//Key
keysIdleTimeout.onKeyDown =
Delegate.create(clsRef,startTimeout);
Key.addListener(keysIdleTimeout);
//Mouse
mouseIdleTimeout.onMouseMove =
Delegate.create(clsRef,startTimeout);
mouseIdleTimeout.onMouseDown =
Delegate.create(clsRef,startTimeout);
Mouse.addListener(mouseIdleTimeout);
}
public function killIdleTimeout() {
trace("killIdleTimeout called");
clearInterval(iTOIntID);
delete iTOIntID;
delete clsRef;
delete intFuncRef;
delete iTOIntDur;
Key.removeListener(keysIdleTimeout);
Mouse.removeListener(mouseIdleTimeout);
}
}
[/code]
-Keith
http://home.mn.rr.com/keithreinfeld
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Randy Tinfow
Sent: Thursday, May 25, 2006 3:07 PM
To: [email protected]
Subject: [Flashcoders] Timeout from Flash page
We've got a Flash intranet app that offers write privileges to the first
user and locks out subsequent concurrent users. Sometimes a user will
walk away without closing the browser or logging out of the app. This
is a problem because the program remains locked indefinitely.
Is there a method in Flash to detect inactivity and forward to a new
page after an interval of time? Tried this with the mouse listener and
it disabled all the buttons.
Any suggestions?
Thanks,
Randy Tinfow
IMAGE PLANT
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com