Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3-preventDefault()不';t全屏工作(空气)_Actionscript 3_Flash_Air - Fatal编程技术网

Actionscript 3 AS3-preventDefault()不';t全屏工作(空气)

Actionscript 3 AS3-preventDefault()不';t全屏工作(空气),actionscript-3,flash,air,Actionscript 3,Flash,Air,我试图在空中制作一个全屏程序,当你按下escape键时,它不会变成窗口。为什么我的程序不能正常工作,如何使它正常工作 代码: }我创建了一个新项目(FlashDevelop),目标是AIR 14(也成功试用了AIR 3.9),该项目包含以下文档类文件: package { import flash.desktop.NativeApplication; import flash.display.NativeWindow; import flash.display.Nati

我试图在空中制作一个全屏程序,当你按下escape键时,它不会变成窗口。为什么我的程序不能正常工作,如何使它正常工作

代码:

}

我创建了一个新项目(FlashDevelop),目标是AIR 14(也成功试用了AIR 3.9),该项目包含以下文档类文件:

package 
{
    import flash.desktop.NativeApplication;
    import flash.display.NativeWindow;
    import flash.display.NativeWindowInitOptions;
    import flash.display.NativeWindowRenderMode;
    import flash.display.NativeWindowSystemChrome;
    import flash.display.Sprite;
    import flash.display.StageDisplayState;
    import flash.events.Event;
    import flash.events.FullScreenEvent;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;
    import flash.ui.Keyboard;

    public class Main extends Sprite 
    {

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            if(e) removeEventListener(Event.ADDED_TO_STAGE, init);

            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyUpHandler);

            var content:Sprite = new Sprite();
            content.graphics.beginFill(0xFFFF00);
            content.graphics.drawRect(0, 0, 400, 500);
            content.graphics.endFill();
            addChild(content);

            this.addEventListener(MouseEvent.CLICK, fullScreen);

            stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
        }

        private function fullScreen(e:Event):void {
            stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
        }

        protected function keyUpHandler(event:KeyboardEvent):void {
            switch(event.keyCode) {
                case Keyboard.ESCAPE:
                    trace("ESCAPE");
                    event.preventDefault();
                    break;

                default:
                    trace("UNHANDLED KEY: ", event.keyCode);
            }
        }


    }

}
它像预期的那样工作。当点击escape时,键事件上的
preventDefault()
方法成功地将应用程序保持在全屏状态

注:

它必须放在钥匙上。钥匙打开没有效果。结果与
stage
nativeApplication

上的向下键侦听器相同。您无法阻止用户转义并全屏退出,这是一种无法绕过的安全性,旨在防止。。。我想做一个全屏模式的游戏,当你按escape时,我想弹出一个菜单。这就是为什么我想阻止进入窗口模式。没有办法做到这一点吗?正如BotMaster告诉你的-没有。至少没有纯AS3。甚至在空气中也没有?对不起,如果我问了很多愚蠢的问题:3这是可能的,但只能从空气开始15。然后必须在esc键、displaystatechange和event.closing上使用preventDefault。
package 
{
    import flash.desktop.NativeApplication;
    import flash.display.NativeWindow;
    import flash.display.NativeWindowInitOptions;
    import flash.display.NativeWindowRenderMode;
    import flash.display.NativeWindowSystemChrome;
    import flash.display.Sprite;
    import flash.display.StageDisplayState;
    import flash.events.Event;
    import flash.events.FullScreenEvent;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;
    import flash.ui.Keyboard;

    public class Main extends Sprite 
    {

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            if(e) removeEventListener(Event.ADDED_TO_STAGE, init);

            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyUpHandler);

            var content:Sprite = new Sprite();
            content.graphics.beginFill(0xFFFF00);
            content.graphics.drawRect(0, 0, 400, 500);
            content.graphics.endFill();
            addChild(content);

            this.addEventListener(MouseEvent.CLICK, fullScreen);

            stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
        }

        private function fullScreen(e:Event):void {
            stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
        }

        protected function keyUpHandler(event:KeyboardEvent):void {
            switch(event.keyCode) {
                case Keyboard.ESCAPE:
                    trace("ESCAPE");
                    event.preventDefault();
                    break;

                default:
                    trace("UNHANDLED KEY: ", event.keyCode);
            }
        }


    }

}