Flash bug when enter fullscreen keyboard events fired - Workaround
For a project I am making a videoplayer which can be controlled by the keyboard. The spacebar is used for toggling between play and pause. But a bug inside the Flashplayer causes my videoplayer to pause or play when entering fullscreen mode. Since this is really anoying I wrote a workaround which seems to be working very nice:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | package { import flash.display.Stage; import flash.events.Event; import flash.events.FullScreenEvent; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import flash.display.MovieClip; /** * @author Thijs Broerse */ public class Main extends MovieClip { public function Main() { this.stage.addEventListener(FullScreenEvent.FULL_SCREEN, this.handleFullScreen, false, int.MAX_VALUE, true); } private function handleFullScreen(event:FullScreenEvent):void { if(event.fullScreen) { event.target.addEventListener(KeyboardEvent.KEY_DOWN, this.handleKeyDown, false, int.MAX_VALUE, true); event.target.addEventListener(Event.ENTER_FRAME, this.handleFrameDelay); } } /** * Stop KeyboardEvent for SPACE, since this one is caused by a bug * http://bugs.adobe.com/jira/browse/FP-814 */ private function handleKeyDown(event:KeyboardEvent):void { if(event.keyCode == Keyboard.SPACE) event.stopImmediatePropagation(); } private function handleFrameDelay(event:Event):void { event.target.removeEventListener(KeyboardEvent.KEY_DOWN, this.handleKeyDown); event.target.removeEventListener(Event.ENTER_FRAME, this.handleFrameDelay); } } } |
After implementing the code above inside your document class, you won’t be bothered again with the KeyboardEvent after fullscreen.
I also included this bugfix inside our Temple Framework so it will automaticly work when using the Temple. Our Temple isn’t available for public now, but we are working on that…
November 12th, 2009 at 20:44
Thanks, I am making game for full screen and was wandering why my hero keeps attacking after full screen.