Simple Session Timeout for Flex App

Web Development, Flex

If you have ever done any development in Flex you know that there isn't a good counterpart to ColdFusion's session management (ie timeout length and such).  So, what do you do if you want to time a user out from a secure are of your Flex application? 

The application in this case is comprised of many individual view components running through one single main view.  So the code in my examples is located in that main view component.

The Timer:

"The Timer class is the interface to Flash Player timers. You can create new Timer objects to run code on a specified time sequence. Use the start() method to start a timer."

Once we have the flash Timer imported we need to create three methods: 

One to initialize the timer, one to call when the timer is finished, and one that resets the timer.  As you can see in the examples, any time the mouse moves the timer is cleared which has the effect of keeping our "session" alive.

The method initTimer() is called upon creationComplete of that main view component.  creationComplete="initTimer()"

public var myTimer:Timer;
			
private function initTimer():void
{
     myTimer = new Timer(300000);
     myTimer.addEventListener("timer",logout);
     this.addEventListener(MouseEvent.MOUSE_MOVE, resetTimer);
     myTimer.start();
}

private function logout(event:Event):void
{

   //place code here to run your log out routine
   
}

private function resetTimer(event:Event):void
{
     myTimer.reset();
     initTimer();	
}

NOTE:  For those wondering, this particular application does not require a session be maintained server side as we reauthenticate each request as it is received.

tags:
Flash, Flex
Robert B?k said:
 
Hi, I've found Your page while searching for a solution to do exactly this. I've also found this: http://inflagrantedelicto.memoryspiral.com/2008/12... which shows a method to use a built in mechanism for checking if the application is Idle. Cheers
 
posted 264 days ago
Add Comment Reply to: this comment OR this thread
 
 
Nice find, thanks Robert.
 
posted 263 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Fuelly