Hiding the Mouse in Flash

Hiding the mouse in a Flash app should be a simple matter of calling flash.ui.Mouse.hide().  This works totally fine in the standalone player.

However, in some browsers that doesn’t actually hide the mouse all the time.  For example, this has been a problem off and on in Chrome/Chromium for some time on various platforms.  In Linux under Chromium (build 20.0.1132.57), I could not figure out any real pattern to making it hide or not using just flash.ui.Mouse.hide().  Sometimes it works, sometimes it doesn’t.  You see this a lot in Flash games that show a custom display list cursor under the native system cursor; the latter didn’t hide properly.

Fortunately, assuming you’re using Flash >= 10.2, there is a seemingly reliable workaround.  Set the mouse cursor to the default cursor (!), then hide the mouse like usual.  E.g., in Haxe/NME:

  nme.ui.Mouse.cursor = flash.ui.MouseCursor.AUTO;
  nme.ui.Mouse.hide();

Note that MouseCursor isn’t wrapped by NME so you need to refer directly to the Flash classpath, and it only works for the flash target.

Setting Mouse.cursor triggers Flash’s native cursor support. Presumably doing that is in turn changing some interaction or state between Flash and the browser, such that Mouse.hide() seems to actually reliably hide the mouse.

In RocketHaxe this happens automatically on the Flash platform, e.g., by calling com.rocketshipgames.haxe.ui.Mouse.disable().