567 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Ireland
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
iamdok says

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?

412 posts
  • Author had a File in an Envato Bundle
  • Beta Tester
  • Bought between 1 and 9 items
  • Brazil
  • Has been a member for 5-6 years
  • Referred between 1 and 9 users
  • Sold between 10 000 and 50 000 dollars
patrickjansen says

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?

1160 posts
  • Author had a File in an Envato Bundle
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 50 and 99 items
FlashTang says

Why Keyboard.ESCAPE ?

if you want to call function

another way
you can add an EventListener : RESIZE
stage.addEventListener(Event.RESIZE,function(e){
                                               if(isFullscreen){
                                                   yourfunction()

                                               }
                                               else{
                                                   yourfunction2()
                                               }

                                               })
567 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Ireland
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
iamdok says

Hi Patrick,

Cheers for your reply, here is the toggle function code:

CODE

Donagh

ps. How are you checking trace statements in the browser?

8112 posts Community Moderator
  • Attended a Community Meetup
  • Community Moderator
  • Has been a member for 6-7 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
+4 more
MSFX Volunteer moderator says
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…

755 posts
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 500 and 999 users
  • Sold between 100 000 and 250 000 dollars
skyplugins says
ps. How are you checking trace statements in the browser?

You can use the remote debugging function in the flash editor.

1160 posts
  • Author had a File in an Envato Bundle
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 50 and 99 items
FlashTang says
Yes, not working in browser,really don’t know why
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" 

    }
}
1312 posts
  • Elite Author
  • Sold between 50 000 and 100 000 dollars
  • Has been a member for 5-6 years
  • Microlancer Beta Tester
  • United Kingdom
  • Attended a Community Meetup
  • Referred between 200 and 499 users
+3 more
LGLab says

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.

1160 posts
  • Author had a File in an Envato Bundle
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 50 and 99 items
FlashTang says
Oh I know why now , maybe it was limited by Adobe
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
   }
}
567 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Ireland
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
iamdok says

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.

by
by
by
by
by
by