javascriptdom-eventsair

Tracking mouse position in Adobe Air using JavaScript


How do I track the mouse cursor position change in Adobe Air using Javascript API in Adobe Air 1.5? The following code doesn't seem to work for me.

var mainWin; //main stage
var _self={};
_self.mouse={x:0,y:0};

//Alias: air.MouseEvent=window.runtime.flash.events.MouseEvent;
mainWin.addEventListener(air.MouseEvent.MOUSE_MOVE,function(e){
    _self.mouse.x=e.pageX;
    _self.mouse.y=e.pageY;
});

What I want to implement is IM-like status change Ready to chat/Away. If there is another way please let me know.


Solution

  • air.NativeApplication.nativeApplication.idleThreshold = 10; //10 seconds idle time
    
    air.NativeApplication.nativeApplication.addEventListener(air.Event.USER_IDLE, function(event) { 
                //away
        }); 
    
    air.NativeApplication.nativeApplication.addEventListener(air.Event.USER_PRESENT, function(event) { 
                //back
        });