How can I tell when a user has been idle for say 5 minutes on my Flex app?
When I say "idle" I mean the user has not interacted with the application at all.
Thanks!!
How can I tell when a user has been idle for say 5 minutes on my Flex app?
When I say "idle" I mean the user has not interacted with the application at all.
Thanks!!
Create a timer that you reset everytime you capture an user event at the application level.
If the timer has ended, then you know the user has been idle for that set amount of time.
// I am capturing only mouseMove and keyDown. That _should_ be enough to handle most user interactions.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" mouseMove="onUserEvent" keyDown="onUserEvent">
...
private function onUserEvent(event:Event):void
{
timer.reset();
}
Being that this is an AIR app, I can just listen for the USER_IDLE event on the NativeApplication
//Set seconds for idle
this.nativeApplication.idleThreshold = 5;
//listen for user idle
this.nativeApplication.addEventListener(Event.USER_IDLE,lock);
See also the idle
event in SystemManager
. This approach works for AIR or Flash Player.
application.systemManager.addEventListener(FlexEvent.IDLE, onIdle);
You can get the idle time (in an unsupported way) using
SystemManager.mx_internal::idleCounter