Posts tagged ‘Event’

Tracking user presence

Adobe AIR applications can detect if user is actively using a computer. The NativeApplication object dispatches two events:
userIdle event – user is not using a computer,
userPresent event – user is using a computer again.
The following lines of code set the idle threshold to 20 seconds and listen for both the userIdle and userPresent events:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    creationComplete="init()" viewSourceURL="srcview/index.html"> 

    <mx:Script>
        <![CDATA[
            private function init():void
            {
                nativeApplication.idleThreshold = 20;
                nativeApplication.addEventListener(Event.USER_IDLE, userIdleHandler);
                nativeApplication.addEventListener(Event.USER_PRESENT, userPresentHandler);
            } 

            private function userIdleHandler(event:Event):void
            {
                trace('idle');
            } 

            private function userPresentHandler(event:Event):void
            {
                trace('present');
            }
        ]]>
    </mx:Script> 

</mx:WindowedApplication>