AIR 1.1 – hiding the mouse cursor
November 16th, 2008 • ActionScript, AIR
Adobe AIR is out quite a while now and you might think that at least all the functions being in the FlashPlayer for years are implemented correctly. Obviously this is only wishful thinking because I wasn’t able to hide my mouse cursor through Mouse.hide() even though the documentation says that it’s possible. I couldn’t reproduce the same thing on Windows so I guess it’s only a problem on OSX and maybe Linux (but who really cares about linux?). After investigating quite a while I found out that the cursor disappears after moving it out of the window and back in or switch to another application and back but you can’t tell the user "please move your cursor out of the window and back in" or at least it’s not very nice and user-friendly. I tried every possible setting for the native window and finally found a workaround … wohoo.
Try the following in your document class and your cursor is gone, hopefully!
stage.nativeWindow.activate(); stage.nativeWindow.orderToBack(); stage.nativeWindow.orderToFront(); Mouse.hide();
Basically this sends the window behind all the other windows and brings it to the front again immediately. You won’t see the change or any flickering. After that you can hide your cursor.
Update 17.11.2008
Adobe just released AIR 1.5 but seems like this problem is still there. The workaround is still working so keep on rockin’ or should I say hiding
16 Responses (Add Your Comment)
-
-
Thanks very much for this fix. One note to add is that the code must execute after fullscreen mode is initiated.
-
Thanks for the tip! Works like a charm!
-
[..] A little unrelated, but I rather liked this site post [..]
-
highrise May 11, 2010at 3:32 pm
Thanks, useful hint.
-
Martin, I found that this works fine as long as you start the AIR application by double click in the Finder. However, if you set the application to automatically start on login the cursor doesn’t hide. (BTW I’m using AIR 2.02 and this still isn’t fixed!)
-
Yep, autostart is screwing up this fix.
(Using Air 2.0)Any idea why?
-
Christopher Burns December 2, 2010at 2:24 am
According to the discussion at:
http://forums.adobe.com/thread/242864“The problem seems to happen because the mouse cursor is in the top left corner of the screen on startup.
If the cursor is here AIR can’t hide it. If I manually move the cursor somewhere else on the screen the fix given seems to work.”This was plaguing me… hopefully this will help someone else out.
-
Had the same problem.
Was working with the solutions posted above,but was not having any luck…
Then it occured to me that these things need to happen in the correct order.Not only does the faked button click gotta happen before the Mouse.hide(),
But it also needs to happen between the orderToBack and orderToFront.Took me forever to figure that little nugget out, and thought I would post this to help someone else with the same troubles.
like this:
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.nativeWindow.activate();
stage.nativeWindow.orderToBack();
dispatchEvent(new MouseEvent(MouseEvent.CLICK));
stage.nativeWindow.orderToFront();
Mouse.hide();
-
none of these suggestions works if you open the air file as a startup item. I’m trying to find a better solution, but there is one way of doing this…
The mouse does hide if you double click to open the file, so you can make an Automator application that does that. Choose “watch me do” then record double clicking on the Air app. You can then speed all this up by choosing 10x.
Still looking for a less messy solution for this though!
-
a slightly less messy solution that makes the Automator app independent of the film:
Record a “watch me do” workflow that moves the mouse and clicks (you can move it and click anywhere, but do it quick to minimize the weirdness!).
Put a delay on the mouse hiding in the actionscript. Because opening times are a bit of an unknown, i hide the mouse a number of times after intervals like so:
function mouseHide0(){
Mouse.hide();
}
setTimeout(mouseHide0, 2000);function mouseHide1(){
Mouse.hide();
}
setTimeout(mouseHide1, 5000);function mouseHide2(){
Mouse.hide();
}
setTimeout(mouseHide2, 10000);
-
gtechnology June 19, 2011at 1:17 am
I’m new to this. Where do Put the code. I am creating a flex project for AIR in Flex Builder 3. Here is the code:
please help I want to hide the cursor. Thanks.
-
gtechnology June 19, 2011at 1:19 am
Guess I can’t do the code, but where do I put it in the .mxml main file.
-
Not to muddle the mixture any further, but I was working on a kiosk app, publishing in AIR 2.6, when i ran into this exact same issue, but the fix wasn’t working on the touch device i was using. To get it to work, I had to reverse the workaround and the command to go fullscreen, like so:
stage.nativeWindow.activate();
stage.nativeWindow.orderToBack();
dispatchEvent(new MouseEvent(MouseEvent.CLICK));
stage.nativeWindow.orderToFront();
Mouse.hide();stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.displayState = StageDisplayState.FULL_SCREEN;I was using an Elo 2700 Intellitouch. hope this saves someone some time.
-
In my case it only worked when the mouse cursor was over the adobe air window when it first opened.
So what I did was first make the window as big as the monitor, and then hide the cursor with the back front trick.
Then you can go fullscreen, or resize the app to some other size. As I needed a fullscreen app this worked beautifully.
Thanks for the tip, but this only got me part way. It failed to work in fullscreen interactive mode on OSX. I noticed that the mouse wouldn’t hide until I clicked somewhere on the stage, so I faked a click with
dispatchEvent( new MouseEvent( MouseEvent.CLICK ) );just before theMouse.hide();