Search code examples
apache-flexairflex4flex4.5

Tracking mouse outside of window in desktop-based app?


I'm returning to Flex/AIR after having been away awhile so this may be a very basic question.

I have a window-based desktop AIR app. It has a sidebar/control panel type feature which is hidden until the user moves the mouse X to < 5 px of the left side of the stage/window. Then if the sidebar is displayed, it gets hidden if the user moves the mouse X to > 220. Simple.

I'm running into a silly problem where the user can move the mouse too quickly to the left, go past the left side of the window and my routine to open the sidebar doesn't get called. I've tried using ENTER_FRAME, MOUSE_MOVE and MOUSE_OUT, alone and in combination but it is still very easy to get the sidebar routine to fail.

this.stage.addEventListener(Event.ENTER_FRAME, controlPanelDisplayHandler);
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, controlPanelDisplayHandler);
this.stage.addEventListener(MouseEvent.MOUSE_OUT, controlPanelDisplayHandler);

In my routine to show/hide the sidebar, I see traces of, say, the ENTER_FRAME event but it holds the last mouseX position it was aware of before the mouse left the window, not the current mouse position within the desktop rect.

I seem to recall there was some security thing around this but it's been quite a while. Can anyone suggest a way I can accomplish this simple feature?

private function controlPanelDisplayHandler(event:Event):void
{
trace("mouseX" + this.stage.mouseX);

if (sidebarDisplayed == false){
    if (mouseX <= 5){ 
        sidebarDisplayed = true;
        showSidebar();  
    }
} else if (sidebarDisplayed == true){

    if (mouseX >= 240){
        sidebarDisplayed = false;
        hideSidebar();  
    }
}

Solution

  • New to Flex as well, and may not be helping, but have you tried Event.MOUSE_LEAVE?

    Might give you the same problem though, not sure.