AS3:退出全屏事件监听器

时间:2014-05-23 13:48:54

标签: actionscript-3 flash events

如何通过按escape键来添加侦听退出全屏事件的事件侦听器?

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

谢谢:)

3 个答案:

答案 0 :(得分:2)

我有这样的感觉。

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;
                }
            }

但你可以改写它。那就是这样......等待......等等

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;
            }
        }
    }
}

答案 1 :(得分:1)

尝试:

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

答案 2 :(得分:1)

stage.addEventListener(FullScreenEvent.FULL_SCREEN等...) 这会触发您是进入还是离开全屏。