actionscript-3 - 当用户更改 Adob​​e AIR 中的屏幕分辨率时如何获取?

标签 actionscript-3 air desktop

我可以在应用程序启动时获取屏幕分辨率,但我可以知道用户何时更改了分辨率吗?

类似事件的东西(示例):

Screen.mainScreen.addEventListener("CHANGE_RESOLUTION", ...)

我尝试使用 setInterval 来监控分辨率,但这是最好的方法吗?

var resolution:Rectangle = Screen.mainScreen.bounds;

setInterval(function():void {

    if(!Screen.mainScreen.bounds.equals(resolution)) {
        trace("changed!");
    }

}, 1000);

最佳答案

据我所知,轮询(您当前正在做的事情)是 AS3 中检测屏幕分辨率变化的唯一方法。

但是,如果您位于最大化或全屏窗口中,则窗口(或舞台,如果设置为 NO_SCALE)将在分辨率更改时触发调整大小事件。 (see the answer from Diniden)。不过我建议监听 stage.nativeWindow 对象而不是 stage 本身。

I'd say that you are doing it a perfectly acceptable way currently.

但请记住,如果这是桌面应用程序,则用户可以在非主显示器 (Screen.mainScreen) 上运行您的程序。为了支持这种情况,您需要执行如下操作:

//a constant to use for a custom event
const RESOLUTION_CHANGE:String = "resolution_change";

var resolution:Rectangle = curScreen.bounds;

//Adobe recommends using timers instead of setInterval - using ENTER_FRAME may be too expensive for your needs, but would afford the quickest reaction time.
var resolutionTimer:Timer = new Timer(1000); //poll every second (adjust to optimum performance for your application)
resolutionTimer.addEventListener(TimerEvent.TIMER, pollScreenResolution);
resolutionTimer.start();

//get the screen that the window is on
function get curScreen():Screen {
    //get the first screen [0] that the current window is on
    return Screen.getScreensForRectangle(stage.nativeWindow.bounds)[0];
}

function pollScreenResolution(e:TimerEvent) {
    if(!curScreen.bounds.equals(resolution)) {
        trace("changed!");
        //dispatch our custom event
        stage.dispatchEvent(new Event(RESOLUTION_CHANGE));
        resolution = curScreen.bounds; //set the resolution to the new resolution so the event only dispatches once.
    }

}

现在您可以在应用程序的其他部分监听该事件。

stage.addEventListener(MovieClip(root).RESOLUTION_CHANGE, doSomething);

关于actionscript-3 - 当用户更改 Adob​​e AIR 中的屏幕分辨率时如何获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47515781/

相关文章:

web-applications - 从 Web 应用程序访问本地文件

c# - 在 windows xp 下检测刷新 Action

java - 如何在java中获取桌面路径

android - 如何在 Android 设备上找到 AIR 应用程序可用的实际区域?

actionscript-3 - 将类导入 ActionScript 文件

actionscript-3 - 从SoundChannel对象AS3 Flash保存声音

actionscript-3 - 录制声音并保存为mp3文件

mysql - 从 Adob​​e flex/AIR 访问 mysql

actionscript-3 - 为什么不播放此嵌入式声音文件?

linux - 以编程方式检查用户是否在桌面 - Linux