Flex example application with view source
Click Here to see the Example


Requirement
Be able to have an object watch for mouse and keyboard activity on a timer.

Resolution
Create a way to count down a dynamic number of minutes and/or seconds that a user is idle in my application and fire off an event when done.

Solution
A developer object that counts down activity on the application or any object in the application or multiple objects. When activity is seen the object resets the timer and starts over couting down.

Explanation
An example appliction is available. You can right click and view view source to see the view source of the application and download the whole example.

The IdleUserObject class extends the container class. It will be used to store the watched objects and reset the timer when there is a mouseover or keydown in the objects being watched.

So, let's get down to the skinny of the IdleUserObject.

I have been using ActionScript and Flex for a short time, so help me out if you see something obvious that I should fix.

Methods:
"StartWatch" - Starts the timer at the intervals specified.

"StopWatch" - Stops the timer and fires the timedout event.

"addListener" - Adds a listener object to the list.

"removeListener" - Removes a listener object from the list.
Values:
"secondsToGo" - keeps track of the number of seconds left until timeout.
Events:
"timedout" - dispatches when the StopWatch method is called or when the timer times out which ever comes first.

"active" - dispatches at every iteration of the clock specified by StartWatch method.

How to use:
1) Create a timeout object using the IdleUserObject class.
<adartautils:idleuserobject id="timeout">

2) Assign actions to the events, so we know when they are fired.
<adartautils:idleuserobject id="timeout" active="txtHeader.text='Running Stop Watch'" timedout="TimedOut()">
</adartautils:idleuserobject>

3) Add some code to our application that will watch on an object "tiObject". The timer will watch for 15 seconds (0.25 minutes) and will tick every 0 minutes and 1 second.

timeout.addListener(tiObject);
timeout.StartWatch(0.25,0,1);
Summary
I see a multitude of ways you could use this object. One example would be to logoff the user after so many minutes and be able to resolve any timeout issues that otherwise would be created on the server. I tried to make this object class as robust as possible, so I can use it in later applications.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5