Using Fullscreen Interactive and Mouse Lock in Flash Player 11.3

Posted on April 24, 2012 | 20 comments

Fullscreen Interactive Feature

In Flash Player 11.3 (currently in beta on labs.adobe.com) there is a new feature that allows applications to use full keyboard input in fullscreen mode.

To use the new fullscreen interactive feature you must first set the “allowFullscreenInteractive=true” value in the HTML embed code. Then in ActionScript you set the display state correctly, stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;, to launch the application into fullscreen interactive mode. This mode presents the user with a slightly different overlay then normal fullscreen mode. It presents the user with an overlay that has an “Allow” button which must be clicked before entering the fullscreen interactive mode. Here is what it looks like:

As a developer you can listen for the new FullScreenEvent.FULL_SCREEN_INTERACTIVE_ACCEPTED event to know when the user has clicked the allowed button.

Mouse Lock Feature

The mouse lock feature is supported in Flash Player 11.2 and beyond. You can only turn on mouse lock, stage.mouseLock = true, while in any fullscreen mode. There is a bug in 11.3 that will be fixed for 11.4 that I’ll explain and show a workaround for 11.3. Since you can only use it in fullscreen mode, it makes sense to set stage.mouseLock = true in the function handler for the FullScreenEvent.FULL_SCREEN_INTERACTIVE_ACCEPTED event. This is where the bug is, if you do set stage.mouseLock = true in that function handler it will not get set correctly, it stays equal to false. That means you have to wait a frame or some amount of time before setting it. In my code example on github I add a flag and then listen on MOUSE_MOVE, which I am doing anyways, to set stage.mouseLock = true. Here is a code snippet:

protected function mouseMoveHandler(event:MouseEvent):void
{
if (isFirstTime == true && stage.mouseLock == false)
{
isFirstTime = false;
errorMessage.text = "here: " + stage.mouseLock;
stage.mouseLock = true;
}
if (stage.mouseLock)
{
errorMessage.text = "here: " + event.movementX;
deltaX = event.movementX;
}
else
{
//deltaX = event.stageX - lastX;
//lastX = event.stageX;
}
}

protected function fullscreenHandler(event:FullScreenEvent):void
{
if (event.type == FullScreenEvent.FULL_SCREEN_INTERACTIVE_ACCEPTED)
{
isFirstTime = true;
//*****
// For Cyril (Flash Player 11.3) this is a bug that mouseLock does not get set to true,
// The workaround is using isFirstTime approach
// Flash Player 11.4 will have a fix for this behavior
//*****
stage.mouseLock = true;

trace("["+event.type+"]Set mouse lock: " + stage.mouseLock);
errorMessage.text = "["+event.type+"]Set mouse lock: " + stage.mouseLock;
}
else
{
isFirstTime = false;
}
}

The full source as a Flash Builder 4.6 project, with modified index.template.html, -swf-version, and latest playerglobal.swc for 11.3 is located on my github repo here.

Here is a running version of the example – http://renaun.com/flash/fullscreeninteractivemouselock/

  • Pingback: Random Walk in Away3D 4.0

  • Jose

    I have some questions, can you help me? I’m afraid the reply is no, but…
    - Is possible to avoid, every time Flash goes Full Screen the “allow” message? Something like “Allow always for this one” or something like that.
    - Is possible to go FULL_SCREEN and go directly to FULL_SCREEN_INTERACTIVE without going back to NORMAL mode?
    - Is possible to customize the message in the top of the Flash when going Full Screen?
    Thanks a lot!

    • Anonymous

      I don’t think there is a setting for accepting full screen interactive once and then never see it again.

      Not sure on going from FULL_SCREEN to FULL_SCREEN_INTERACTIVE, but should be easy to test.

      No you can’t customize the allow message.

      • Jose

        Is what I afraid, thanks for your reply Renaun!

  • Ali

    Allow? Seriously? Allow what? what’s the point of asking for permission to access the Keyborad? What can happen in fullscreen mode that can not happen in normal mode? we already have access to keyboard in normal mode why restrict it in fullscreen and then ask user to “Allow”? It will just scare the users for nothing. I just can’t understand. Hope Adobe removes it.

    • Anonymous

      The security issue is if someone made a fullscreen application that looked like your desktop and asked for login credentials.

  • Linda

    Hi i cant seem to get the option FULL_SCREEN_INTERACTIVE. What can i do to get this.

    • Anonymous

      Do you have Flash Player 11.3?
      Compiled your swf with the right swf-version?
      Added the appropriate embed options?

      • Linda

        Thank you, i wasnt compiling with the right swf. Am not sure if i am understanding this well but i currently have a button and on the click event i am setting this
        stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;

        Problem is nothing happens i dont get the full screen and the allow pop up, but if i use this option
        stage.displayState = StageDisplayState.FULL_SCREEN
        i get the full screen but i dont get the allow pop up.
        Please help!Thank you.

        • Anonymous

          What does you HTML code look like?

          • Linda

            I am currently running the application straight from flash builder, do i need to embed it my html file that is in my bin-debug?

          • Linda

            I am new in flex and might be asking all the stupid questions. The html file in my debug folder is generated so i wont be able to edit anything. I just had a look at it and its got :

            params.allowfullscreen = “true”;

            If i am running straight from flash builder what should i do to get the full screen working?

          • Linda

            Hi i managed have managed to change my html file and it now works. Thank you for your help.

  • Anonymous

    That is pretty vague, I would submit it as a bug here: http://bugs.adobe.com/flashplayer/

  • Nomusa

    Hi , i have added the fullscreen keyboard input functionality in one of my projects . When i first click the fullscreen button the allow message pops up and when i allow i am able to enter text in my input boxes. If i click esc after that then go back and click the fullscreen button nothing happens i dont get the allow popup. its almost as if its caching that allow. I seem to have this problem with IE9 but on firefox i havent experienced it. If anyone knows something about this please help.

  • Donald

    Hi, i have added fullscreen interactive functionality to my application. It works fine in firefox but doesnt in IE 9.08 . In IE i dont get the allow popup at all. When i added a try catch i got an error 2152 . What am i doing wrong? This is my actionscript

    if (this.stage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE)
    this.stage.displayState=StageDisplayState.NORMAL;
    else
    this.stage.displayState=StageDisplayState.FULL_SCREEN_INTERACTIVE; andin my html file i added the following

    params.allowFullScreenInteractive = “true”;

    Am using flash player 11.4.

    • Anonymous

      Double check that you are using 11.4 with IE. And try using swfobject.js for the html embed with the right flag to allow fullscreen interactive.

      • oyzm

        I got the same problem.when ie F5 refreshed, the fullScreen code throw error #2152.

        • Santosh Bhoyar

          did you get any fixes for this issue.. I am experiencing the same issue.

  • Mahmoud Essa

    thank you for you amazing article

    please how i can avoid remove popup message when i make full screan

  • aerian

    hi. i am running an external sandisk cruizer glide with snowlinux 4 due to my hard drive being funky. it works fine. i use chromium browser. my issue is also with interactive flash player not allowing hotkeys. when i enter fullscreen on chromium in my MMO browser based game, it does not show an allow function.
    any tips on how to make the fullscreen interactive work with my setup?