Flex - IdleManager

This is an Idle manager built for flex that allows you to automate events when your application has gone idle for a specified amount of time.  I recently found out this IdleManager was in use in the NFL video player.

It allows you to -

  • Add a recurring event that fires ever N number of milliseconds when the app goes idle
  • Add a one time idle event that fires one time the next time the application goes idle and reaches that number of milliseconds - then delete the listener
  • Add an event that will be fired one time every time the application goes idle and reaches that number of milliseconds

USAGE

private function initIdleListeners():void{
//you can pass an optional data object to any of these methods that will be passed with the event
IdleManager.getInstance().addFirstTimeIdleEventListener(1000, firstTimeHandler);
IdleManager.getInstance().addOneTimeIdleEventListener(3000, oneTimeHandler);
IdleManager.getInstance().addRecurringIdleEventListener(5000, recurringHandler);
}
 
private function firstTimeHandler(e:IdleEvent):void{
trace('This is fired every time the app idles for the specified amount of time, just ONCE');
trace(e.millisecondsIdle, e.type, e.data);
}
 
private function oneTimeHandler(e:IdleEvent):void{
trace('This is fired exactly once, the first time the app ever goes idle for the specified amount of time, then is deleted');
trace(e.millisecondsIdle, e.type, e.data);
}
 
private function recurringHandler(e:IdleEvent):void{
trace('This is fired recurringly every time the app goes idle for the specified amount of time');
trace(e.millisecondsIdle, e.type, e.data);
}

You can view the source HERE

Please leave any comments or questions below.

Thanks

TAGS: None

2 Responses to “Flex - IdleManager”


  1. michelle
    on Jan 13th, 2009
    @ 12:05 am

    Hi there,

    i’m tried importing the codes into my project, but i’ve got 3 errors “1046: Type was not found or was not a compile-time constant: IdleEvent.” in the ADLibrary.mxml

    Is there any reason why?


  2. eric
    on Jan 13th, 2009
    @ 7:10 am

    @michelle
    What class is this happening in, it’s imported correctly in all of the classes you’ve imported
    If you’re using the class yourself, you’ll want to import it with the following directive

    import com.appdivision.manager.idlemanager.event.IdleEvent;

    I didn’t include ADLibrary.mxml in the source for the idleManager…so that means youve created it yourself and probably just forgot to import the event. Please post again if you have any questions

Leave a Reply