Introducing Mouse lock, right and middle click events by Thibault Imbert

Free your mouse!We just released on Adobe Labs, Flash Player 11.2 and AIR 3.2 (beta 2) builds.

Note that you guys now have access to standalone debugger builds. Yeah, I know. After 4 years, it was about time! The cool news is that those builds introduce a few cool new features, like mouse lock, right and middle click events and the ability to disable the context menu entirely.

Mouse lock:

A new mouseLock property has been added to Stage. To enable mouse locking set Stage.mouseLock to true. There are several rules which are applied here:

  • This property can only be set in full screen mode.
  • It dispatches a runtime exception if it is called in non-full screen mode.
  • On mobile settings this property always throws an exception. The reason is simple: This feature can only work with a mouse typeof devices and mobile devices do not have such a thing.
  • The property can be read in non-full screen mode. This allows developers to easily dispatch to alternative input methods if mouse locking is disabled externally for some reason.
  • When exiting full screen mode Stage.mouseLock is automatically set to false. Note that while in full screen mode mouse event listeners attached to other display objects but the stage will not be dispatched.
  • In other words to receive mouse deltas and any other mouse event while mouseLock is active you need to attach your mouse event listeners to the stage.

Relative mouse coordinates - New properties (movementX and movementY) on MouseEvent:

When Stage.mouseLock == true:

  • MouseEvent.localX and MouseEvent.localY will contain 0.MouseEvent.movementX and MouseEvent.movementY will contain delta values.
  • MouseEvent.movementX and MouseEvent.movementY are never transformed based on stage transformation, i.e. they always remain in screen space.
  • MouseEvent.movementX and MouseEvent.movementY will be 0 when Stage.mouseLock == false.

Situations where mouse locking is disabled automatically and the mouse cursor is made visible again:

  • When the user hits ESC.
  • When the window loses focus, for instance when the user hit CTRL-TAB.
  • When any settings UI is visible (that includes all privacy dialogs). When a native dialog is shown, for instance a file upload dialog.

Right and middle click events:

Just like with Adobe AIR, right and middle click events can now be used to inside Flash Player. When a listener is registered to the MouseEvent.RIGHT_CLICK event, the native context menu will not show up, allowing you tocreate your own context menu.

I am sure you guys will make good use of that! :)

Comments (42)

  1. Si ++ wrote::

    YAY!

    Tuesday, November 22, 2011 at 10:05 pm #
  2. focus wrote::

    Finally! Thank you, Thibault and other Adobe FP Runtime developers! This is a really expected and needed feature nowadays!

    Tuesday, November 22, 2011 at 10:09 pm #
  3. Daganev wrote::

    Why can’t deltaX and deltaY exist outside of a mouselock situation?

    Tuesday, November 22, 2011 at 10:11 pm #
  4. Henke37 wrote::

    Took you long enough!

    Tuesday, November 22, 2011 at 10:27 pm #
  5. Tyler Egeto wrote::

    Awesome, this looks great. Any ETA on when we’ll see a beta for Stage3D on mobile platforms? I know its scheduled for release early next year, but it would be great to get our hands on that soon.

    Tuesday, November 22, 2011 at 10:41 pm #
  6. serhatsezer wrote::

    There is still a work for performance.
    What a pain and sad.

    Tuesday, November 22, 2011 at 10:47 pm #
  7. Anthony wrote::

    mouselock only in fullscreen? come on really? any reason why?

    Tuesday, November 22, 2011 at 11:46 pm #
  8. ben w wrote::

    fantastic stuff!

    really feels like flash is getting some serious momentum :)

    now to beef up as3 performance wise you we have ourselves one hell of a platform to play with!

    Wednesday, November 23, 2011 at 12:26 am #
  9. tlecoz wrote::

    Salut Thibault,

    (désolé de parler en français mais je n’arrive pas à le formuler en anglais)

    Cela pourrait être vraiment utile d’autoriser l’usage de la ‘free-mouse’ en dehors du mode full-screen.

    Des que l’on remplace le pointeur de la souris par un DisplayObject et que l’on applique une contrainte physique sur cet objet (une répulsion par exemple), la position réelle de la souris ne correspond plus à la position de l’objet et il y a de forte chance que l’utilisateur fasse sortir la souris de l’animation involontairement.

    J’ai été confronté à ce problème pas plus tard que la semaine dernière, et je me disais justement que cette fonctionnalité serait super utile dans ce cas.

    Cela pourrait également être utile dans le cas de bannière qui réagirait au mouvement de la souris de l’utilisateur sans que l’internaute n’aie besoin de mettre sa souris dedans.

    Idem avec un site composé de plusieurs iframe.

    Merci d’avance !

    Wednesday, November 23, 2011 at 9:55 am #
  10. gloomyBrain wrote::

    Anthony, it’s perfectly clear that some security stuff is the reason.
    Glad to see FlashPlayer becoming the HUGE thing =) Thanks, Thibault

    Wednesday, November 23, 2011 at 10:15 am #
  11. Mike P wrote::

    Anthony: Think about it this way: assume some random bit of Flash wanted to lock the mouse the minute it loaded with no means of releasing it. How do you handle that? What about when multiple SWFs want to lock the mouse at once with no user interaction?

    Now, think somewhat deeper. What happens if someone wanted to do bad things with that like forcing a screen-sized window that locks your mouse with no way to escape and also keeps keyboard focus? It would be quite a mess.

    Restricting the mouse lock to full screen mode at least assures a means of escape from what would otherwise become a nightmare. Sure, there could be better ways of handling it but at least this means that the user has to 1) authorize the locking of the mouse by going into full screen mode and 2) the “exit full screen” functionality offers a way to free it up.

    Hope this helps.

    Wednesday, November 23, 2011 at 10:16 am #
  12. loopia wrote::

    So why only mouselock in fullscreen? I can understand you don´t want banners and stuff to lock the mouse. But couldn´t mouslock be “allowed” by some embed setting? Like allowFullscreen… allowMouselock..?

    Wednesday, November 23, 2011 at 10:38 am #
  13. telemacus wrote::

    on osx where do we install the 11.2 debug player ?
    tx.

    Wednesday, November 23, 2011 at 12:20 pm #
  14. 3rlend wrote::

    Is the right clicking only in full screen mode? Hope not.

    Wednesday, November 23, 2011 at 2:34 pm #
  15. That’s about time!

    Glad to see you’re catching up to the things you should’ve done a long time ago!

    Wednesday, November 23, 2011 at 3:59 pm #
  16. Jerome wrote::

    MouseEvent.MIDDLE_DRAG_OVER
    MouseEvent.RIGHT_RELEASE_OUTSIDE
    Wow!

    ;)

    Wednesday, November 23, 2011 at 4:02 pm #
  17. Daniel wrote::

    >On mobile settings this property always throws an exception. The reason is simple: This feature can only work with a mouse typeof devices and mobile devices do not have such a thing.

    There are plenty of Android devices that let you connect a mouse. Playbook does as well?

    Wednesday, November 23, 2011 at 4:50 pm #
  18. michel wrote::

    Thanks for the update. Wonderful.

    I guess it’s not the right place to do that but here I go anyway: is it planned to include SVG support in Air 3.2?

    Wednesday, November 23, 2011 at 5:11 pm #
  19. Otto wrote::

    Rightclick! Finally! Nice to see, yippee =D

    “FAQ
    When will the final version of Flash Player 11.2 be available?

    The final version of Flash Player 11.2 will be released in first half of 2012.”

    @Thibault: Can you concretize this, pls? Jan-Mar or Apr-Jun?

    Wednesday, November 23, 2011 at 6:14 pm #
  20. zeh wrote::

    Thanks!

    Not to rain on the parade, but I’d just like to know the reasoning behind not having a 64 bit version of the debugger players. It sorta breaks my development workflow (FDT 5 on Windows 7, using IE as the external viewer – forces the 64bit version of IE, which doesn’t run the 32 bit version of the player).

    Wednesday, November 23, 2011 at 6:21 pm #
  21. Mediamonkey wrote::

    But what was the original reasoning behind Adobe’s decision to restrict the mouse to LMB only, until now? I’m really curious about that.

    Wednesday, November 23, 2011 at 7:36 pm #
  22. Tronster wrote::

    There has been some ramblings about support for the existing set of Alchemy byte codes being removed from 11.2. Is this true?

    Thursday, November 24, 2011 at 12:12 am #
  23. Thibault Imbert wrote::

    Hi Tronster,

    We are not removing those. It is just that, in the future you will have to be using Alchemy 2. Alchemy 1 will not work in Flash Player 11.2 or AIR 3.2, when playing content above swf version 13 (FP11/AIR3).

    More details here : http://blogs.adobe.com/flashplayer/2011/09/updates-from-the-lab.html

    Now we know there are some concerns regarding people using third-party tools like haXe or Apparat using the opcodes but not interested in C/C++ cross compilation. We don’t have a solution now, but we will soon.

    Thibault

    Thursday, November 24, 2011 at 2:50 am #
  24. alx wrote::

    Well, fuck you and fuck adobe.

    Thursday, November 24, 2011 at 5:53 am #
  25. sascha wrote::

    Thumbs up for these features! But are there any plans to allow mouse locking in non-fullscreen mode at least for AIR builds ? The limitation for web builds is understandable but for AIR builds this should be the case.

    Thursday, November 24, 2011 at 7:15 am #
  26. sascha wrote::

    *should NOT be the case.

    Thursday, November 24, 2011 at 7:16 am #
  27. jloa wrote::

    “right and middle click events and the ability to disable the context menu entirely”

    Aaa! Hell yeah! Finally u did it! You’re the man! Congrats 2 all ^_^

    Thursday, November 24, 2011 at 11:06 am #
  28. Davide wrote::

    Great! Any change to have setMousePos(x,y)?

    Need to talk with you by mail dudes.

    Greetings!

    Thursday, November 24, 2011 at 12:04 pm #
  29. NemoStein wrote::

    “But are there any plans to allow mouse locking in non-fullscreen mode at least for AIR builds?”

    This makes sense. I totally agree!

    The next point now is free the keyboard in fullscreen on FP.
    Let’s bring AAA FPS to the browser!

    Thursday, November 24, 2011 at 1:44 pm #
  30. Pleh wrote::

    Finally! Right click :-) sadly, this has made my day! :-)

    Thursday, November 24, 2011 at 1:58 pm #
  31. Skylab wrote::

    Does anyone how to unlock “Mouse lock”? =/
    Problem with the Facebook game (Zombie Lane), the mouse is constantly locked in the middle.

    Friday, November 25, 2011 at 6:24 pm #
  32. Philip wrote::

    This is great and all, but what about support for more keys in full screen mode?

    Mouselock as is is good, but being able to press WASD while in full screen while mouse locked would really rock!

    Saturday, November 26, 2011 at 5:41 am #
  33. raw wrote::

    First of all, I want to congratulate you guys for making this finally available.

    I understand the reasoning of not allowing mouselock while not in fullscreen but could this be made available for Projectors when they’re in windowed mode?
    Also please make Escape not cancel FullScreen mode in Projectors and allow all keys?

    And are you planning to expand the projectors? I know about AIR, but it isn’t really that flexible and requires extra setup. At least make it so the Projector window has custom title/icon, set if window is maximizable/resizable and no main menu appears on top?

    Sunday, November 27, 2011 at 8:24 am #
  34. Shane wrote::

    This is real exciting. Any possibility that the keyboard will be freed up in 11.2? Seems to go hand-in-hand with mouse lock for first person shooter games. A must have if Flash is to be the “console of the web”.

    Tuesday, November 29, 2011 at 11:14 pm #
  35. Cedric wrote::

    Libérez le clavier en plein écran !!!!

    Free the keyboard in fullscreen !!!!

    Sunday, December 11, 2011 at 2:25 pm #
  36. Thibault Imbert wrote::

    Hi guys,

    For full keyboard access in fullscreen, this is definitely high priority on the list. It seems logical evolution to provide this in the near future. I will keep you guys updated here asap.

    For mouse lock in windowed mode, we designed the APIs to allow this use-case in the future. We wanted to deliver this feature asap, so we decided with fullscreen only for the phase 1. We have a phase 2 in mind for sure.

    Thibault

    Thursday, December 29, 2011 at 9:59 am #
  37. Thibault Imbert wrote::

    Hi Raw,

    Yes, we still do care about projectors. We have some ideas on how we could extend them in the future. Good idea regarding the specific behavior when in projector mode. I will check about this.

    Thibault

    Thursday, December 29, 2011 at 10:01 am #
  38. jfab wrote::

    Hey there, this is wonderful but stage3D isn’t working with swf version 15 (well Alternativa3D 8 ISN’T, so this feature is useless with this engine). Do you know any workaround?
    Thanks!

    Saturday, January 7, 2012 at 12:54 am #
  39. Jeff wrote::

    Hi Thibault,

    Thanks for all the work done since years. There is a critical issue concerning stagevideo memory leak. I’m stuck with this problem no workaround.

    https://bugbase.adobe.com/index.cfm?event=bug&id=3007608

    Regards,

    Jeff

    Monday, January 9, 2012 at 5:13 pm #
  40. DaveW wrote::

    Why does enabling mouselock on mobile always throw an exception? You can use a mouse on tablet devices like the PlayBook and Transformer.

    Thursday, February 2, 2012 at 2:03 am #
  41. Joel Marks wrote::

    Awesome features, thanks for implementing.

    We would like to replace the default context menu using this strategy. Is there any way to still have the ability to get paste from the clipboard to work if we roll our own context menu?

    We have a lot of users that use paste from the context menu and if we took that away they would be none too happy.

    Monday, July 2, 2012 at 8:44 pm #
  42. podlium wrote::

    Hi, the right and middle mouse aint working in FP11.2, i tried it in Flash CS6 with FP11.2 and nothing happens, only right mouse locks up the built in menu… But in a browser with 11.3 it works…? Is there a way to update Flash CS6 to new FP?

    Friday, August 31, 2012 at 7:34 pm #

Trackbacks/Pingbacks (3)

  1. MouseLock nel FlashPlayer | MatitaLabs on Wednesday, November 23, 2011 at 12:55 pm

    [...] ByteArray.org flash [...]

     
  2. First Person Interaction For Flash Please! | Pete Shand on Saturday, December 17, 2011 at 7:34 am

    [...] This feature has now been added to flash 11.2. you can read more about it here: http://www.bytearray.org/?p=3755 [...]

     
  3. [...] can take a closer look at it in this post from Thibault Imbert. This entry was posted on Wednesday, November 23rd, 2011 at 5:33 pm and [...]