Fun with code (since 2006)

Introducing Mouse lock, right and middle click events


11.22.11 Posted in Actionscript 3, Flash Player by

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! :)



45 Responses to “Introducing Mouse lock, right and middle click events”

  1. focus says:

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

  2. Daganev says:

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

  3. Henke37 says:

    Took you long enough!

  4. Tyler Egeto says:

    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.

  5. serhatsezer says:

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

  6. Anthony says:

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

  7. ben w says:

    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!

  8. tlecoz says:

    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 !

  9. gloomyBrain says:

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

  10. Mike P says:

    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.

  11. loopia says:

    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..?

  12. telemacus says:

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

  13. 3rlend says:

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

  14. That’s about time!

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

  15. Jerome says:

    MouseEvent.MIDDLE_DRAG_OVER
    MouseEvent.RIGHT_RELEASE_OUTSIDE
    Wow!

    ;)

  16. Daniel says:

    >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?

  17. michel says:

    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?

  18. Otto says:

    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?

  19. zeh says:

    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).

  20. Mediamonkey says:

    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.

  21. Tronster says:

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

  22. Thibault Imbert says:

    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

  23. alx says:

    Well, fuck you and fuck adobe.

  24. sascha says:

    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.

  25. sascha says:

    *should NOT be the case.

  26. jloa says:

    “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 ^_^

  27. Davide says:

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

    Need to talk with you by mail dudes.

    Greetings!

  28. NemoStein says:

    “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!

  29. Pleh says:

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

  30. Skylab says:

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

  31. Philip says:

    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!

  32. raw says:

    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?

  33. Shane says:

    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”.

  34. Cedric says:

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

    Free the keyboard in fullscreen !!!!

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

     
  36. Thibault Imbert says:

    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

  37. Thibault Imbert says:

    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

  38. jfab says:

    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!

  39. Jeff says:

    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

  40. DaveW says:

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

  41. [...] 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 [...]

     
  42. Joel Marks says:

    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.

  43. podlium says:

    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?

Leave a Reply

Open Sort Options

Sort comments by:
  • * Applied after refresh

ByteArray.org
Fun with code since 2006.