emrahgunduz
always eats his vegetables
Blog RSS Feed
  • twitter
  • friendfeed
  • linkedin
  • facebook
  • vimeo
  • flickr
  • lastfm

Detecting Exit on Fullscreen Flash

If you are still using Actionscript 2 in some projects like me, you may be having problems with detecting an exit from fullscreen, when the user presses the ESC key. For securtity reasons Flash Player control does not let you detect keystrokes in fullscreen mode. Player 10 and AS3 lets you detect cursor keys, and some other ones for game development, but that’s all.

//Here is how you can enable the fullscreen in Actionscript 2 Stage.displayState = "fullScreen"; //and to return to normal Stage.displayState = "normal";
Just changing the display state… It is simple.

But here is the problem. Even though button related screen size changes can be handled by code, Flash does not let you know if the user pressed ESC to exit the fullscreen mode. So, you need a little hack:

//Here is how you can enable the fullscreen in Actionscript 2 Stage.addListener(this); Stage.displayState = "fullScreen";   //and to return to the normal Stage.removeListener(this); Stage.displayState = "normal";
We just added a simple listener to cache what is happening to displayState. Put these codes to a boolean function if you want, or attach to a button onRelease event. Something like a simple function will work for changing the fullscreen on and off:

private function FullScreen(Set:Boolean) {   if(Set) {     Stage.addListener(this);     Stage.displayState = "fullScreen";     //Your on fullscreen code    } else {     Stage.removeListener(this);     Stage.displayState = "normal";     //Your on normal screen code    } }
We can not detect the ESC key at the moment. For that we need a new function. Remember that we attached a listener to the Stage class (actually itself).

private function onFullScreen(is_fullscreen:Boolean) {   if(!is_fullscreen) {     FullScreen(false);   } }
Stage class throws a few events on stage changes. One is a boolean, “onFullScreen”. If you start listening the Stage and cache this event you can detect if the user exited from fullscreen.

This post's short url is: http://emrg.me/5g

Calendar

May 2012
M T W T F S S
« Feb    
 123456
78910111213
14151617181920
21222324252627
28293031  
Web Analytics
Author: Emrah Gunduz