Using Fullscreen Interactive and Mouse Lock in Flash Player 11.3
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:
{
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