通过Actionscript3在Flash中按键切换全屏视图

时间:2015-12-29 14:48:33

标签: actionscript-3 flash-cs6

下面是我的代码,旨在让我的Flash内容在按空格键的同时在全屏视图和普通视图之间切换,到目前为止还没有编译器错误仍无效。

import flash.events.KeyboardEvent;

stage.addEventListener (KeyboardEvent.KEY_DOWN, toggleScreenview);
function toggleScreenview(e:KeyboardEvent):void {
    if (e.keyCode == Keyboard.SPACE){
        stage.displayState = StageDisplayState.FULL_SCREEN;
    } else {
    stage.displayState = StageDisplayState.NORMAL;
    }
}

1 个答案:

答案 0 :(得分:0)

使用StageDisplayState.FULL_SCREEN_INTERACTIVE,此示例使用空格键,如果全屏恢复正常,如果正常则转到全屏

您的解决方案是:

import flash.events.KeyboardEvent;
stage.addEventListener(KeyboardEvent.KEY_DOWN, toggleScreenview);
function toggleScreenview(e:KeyboardEvent):void
{
    if (e.keyCode == Keyboard.SPACE)
    {

        if(stage.displayState == StageDisplayState.NORMAL)
        {
            stage.displayState=StageDisplayState.FULL_SCREEN_INTERACTIVE;
        }

        else
        {
            stage.displayState=StageDisplayState.NORMAL;
        }
    }
}

祝你好运