Ahmed
Ahmed

Reputation: 45

AS3: Exit full screen event listener

How to add an event listener that listens to the exit full screen event by pressing escape key ??

stage.addEventListener(Event.RESIZE, backtoresize)  //doesn't work :(

Thanks :)

Upvotes: 1

Views: 2046

Answers (3)

BotMaster
BotMaster

Reputation: 2223

stage.addEventListener(FullScreenEvent.FULL_SCREEN, etc ...) This triggers whether you enter or leave fullscreen.

Upvotes: 1

Pepin
Pepin

Reputation: 31

I had it like this.

mcVideoControls.btnFullscreen.addEventListener(MouseEvent.CLICK, fullscreenClicked);



function fullscreenClicked(e:MouseEvent):void {
                //fullscreen works only with an internet browser
                if (stage.displayState == StageDisplayState.NORMAL) {
                    stage.displayState = StageDisplayState.FULL_SCREEN;
                } 
                else {
                    stage.displayState = StageDisplayState.NORMAL;
                }
            }

But you could rewrite it. It would then be something like this.... wait hang on...

package {
    import flash.display.Stage;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;

    public class UserInputHandler{  
        //escape button var
        public static var keyEscape:Boolean;

        public function UserInputHandler(stage:Stage){
            //this events are sending the value true when specific keyboard button is pressed to the stage.
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
        }
        //you can provide more key codes in the function
        private function keyDownHandler(e:KeyboardEvent):void{  
            switch(e.keyCode){
                case Keyboard.ESCAPE:
                    UserInputHandler.keyEscape = true;
                    break;

            }
        }
        //function when key is released from pressing
        private function keyUpHandler(e:KeyboardEvent):void{
            switch(e.keyCode){
                case Keyboard.ESCAPE:
                    keyEscape = false;
                    break;
            }
        }
    }
}

Upvotes: 2

inverse
inverse

Reputation: 358

Try:

stage.nativeWindow.addEventListener(Event.RESIZE, backtoresize);

Upvotes: 1

Related Questions