Flex SystemManger monitors whether users are dealing with programs
Source: Internet
Author: User
For example:
Var sysMan: SystemManager = Application. application. systemManager;
SysMan. removeEventListener (FlexEvent. IDLE, timeoutHandler );
// Timeout after twenty seconds
Public var timeout: Number = 20000;
Private var timeoutTotal: Number = 0;
Private var timeoutLastCall: Number;
Public var sessionExpired: Boolean = false;
Public var enableTimeout: Boolean = true;
Private function timeoutHandler (event: FlexEvent): void
{
// Get current time
Var curTime: int = getTimer ();
Var timeDiff: int = 0;
If (isNaN (timeoutLastCall )){
TimeoutLastCall = curTime;
}
TimeDiff = curTime-timeoutLastCall;
TimeoutLastCall = curTime;
// If time has passed since the idle event we assume user is interacting
// Reset time total-otherwise increment total idle time
If (timeDiff & gt; 1000 ){
TimeoutTotal = 0;
}
Else {
// Update time
// The status field will not be updated unless the application is idle
// It is only display a countdown for learning purposes
TimeoutTotal ++ = 100;
Status. text = "Timeout in" + String (Number (timeout-timeoutTotal)/1000). toFixed (0) + "seconds ";
}
// If the total time of inactivity passes our timeout
// And the session already hasn' t expired then logout user
If (timeoutTotal> timeout &&! SessionExpired ){
// Logout user
// Or set flag
SessionExpired = true;
Status. text = "timeout threshold has been reached ";
// Statement executed after the time limit is exceeded
SessionTimeoutHandler ();
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.