Hi All,
I’m experiencing some strange behavior in a Flash project on which I’m working.
I’m listening for the Escape key (keyCode = 27) press while in Fullscreen mode with AS3 . I wish to call a function when the escape key is used to exit the fullscreen mode.
Here is the code for the handler function, but the function works perfectly when testing in Flash Player so I don’t think there are problems there. The problem occurs when I’m testing in the browsers, it seems that the KeyDown event is not being received by the function.
I’m guessing it has something to do with focus but it doesn’t matter where or how may times I click while in fullscreen mode, the event is still not received when the escape key has been pressed.
Escape key is available in fullscreen mode. charCode is 27 or Keyboard.ESCAPE
index file is also using MacMouseWheelScroll by pixelbreaker & SWFAddress & SWFObject 2.0
Any ideas?
you code does trigger / trace in browser (tested not in fullscreen mode). Can you post the fullscreenToggle() function you use to see if it still fires in fullscreen?
Why Keyboard.ESCAPE ?
if you want to call function
you can add an EventListener : RESIZE
stage.addEventListener(Event.RESIZE,function(e){
if(isFullscreen){
yourfunction()
}
else{
yourfunction2()
}
})
- Attended a Community Meetup
- Community Moderator
- Has been a member for 5-6 years
- United Kingdom
- Contributed a Tutorial to a Tuts+ Site
- Won a Competition
- Contributed a Blog Post
- Beta Tester
- Bought between 50 and 99 items
ps. How are you checking trace statements in the browser?
you can use Demonster Debugger to debug a running SWF outside of the IDE …
theres a tutorial at gotoandlearn for it as well…
ps. How are you checking trace statements in the browser?
You can use the remote debugging function in the flash editor.
so your can use RESIZE event ,it works I ‘ve tried
put a text name it “_txt”
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
stage.addEventListener(Event.RESIZE,resizeHandler)
function resizeHandler(e){
if(stage.displayState ==StageDisplayState.NORMAL){
_txt.text="NORMAL"
}else{
}
}
function keyHandler(e:KeyboardEvent):void {
if(e.keyCode==Keyboard.ESCAPE){
fullscreenOff.visible = false;
fullscreenOn.visible = true;
_txt.text="NORMAL"
}
}
fullscreenOff.addEventListener(MouseEvent.MOUSE_DOWN,fullscreenToggle)
fullscreenOn.addEventListener(MouseEvent.MOUSE_DOWN,fullscreenToggle)
fullscreenOff.visible = false;
function fullscreenToggle(e):void {
if(stage.displayState ==StageDisplayState.NORMAL){
stage.displayState=StageDisplayState.FULL_SCREEN
fullscreenOff.visible = true;
fullscreenOn.visible = false;
_txt.text="FULL_SCREEN"
}else{
stage.displayState=StageDisplayState.NORMAL
fullscreenOff.visible = false;
fullscreenOn.visible = true;
_txt.text="NORMAL"
}
}
- Sold between 50 000 and 100 000 dollars
- Has been a member for 4-5 years
- Microlancer Beta Tester
- United Kingdom
- Attended a Community Meetup
- Author was Featured
- Item was Featured
- Referred between 200 and 499 users
isn’t most keyboard input disabled in full screen due to flash player security etc ? I don’t think you can listen to escape keydown.
Think about below code ,what is the aftermath ? you can try it (perss ESC key,in SAflashplayer)
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);
function keyHandler(e:KeyboardEvent):void {
//trace("charCode= " + e.keyCode);
if(e.keyCode==Keyboard.ESCAPE){
fullscreenToggle()
}
}
function fullscreenToggle():void {
if(stage.displayState ==StageDisplayState.NORMAL){
stage.displayState=StageDisplayState.FULL_SCREEN
}else{
stage.displayState=StageDisplayState.NORMAL
}
}
Hey FlashTang,
Thanks man for your work and your testing. Your resize event did the trick
, but I am almost certain I got something like this working in the past (listening for the escape key), but I just wasn’t happening for me this time.
It’s true that text input is disabled but the escape key is an exception, but I’m not clear about whether you can listen to it. My trace statments from remote debugging (Thanks guys for the advice
) were actually returning a keyCode of 32 for the escape key when pressed to exit fulscreen mode, 32 is the code for the space Bar! Not sure why this was happening.
You could be right FlashTang, as the security measures are in place to prevent users from being forced to stay in fullscreen mode. And your code shows an easy exploit of this, if we were able to listen to the escape key.
Thanks to all for their input. Appreciate it.
Happy Flashing,
Donagh.
