【问题标题】:Show Window on largest screen using Adobe AIR使用 Adob​​e AIR 在最大屏幕上显示窗口
【发布时间】:2014-06-13 15:25:15
【问题描述】:

我正在用 HTML/JavaScript 构建一个 Adob​​e AIR 应用程序,它将使用两个窗口,其中一个窗口将显示在可用的最大屏幕上(如果可用)。

代码如下:

function showProjector(){

    if(air.Screen.screens.length > 1) {

        if(htmlLoader) {

            // Projector is already shown

        } else {

            // Create a new window that will become the projector screen
            var options = new air.NativeWindowInitOptions(); 
            options.systemChrome = air.NativeWindowSystemChrome.NONE; 
            options.transparent = true;
            options.type= air.NativeWindowType.LIGHTWEIGHT;

            var htmlLoader = air.HTMLLoader.createRootWindow(false, options, false);  
            htmlLoader.window.nativeWindow.visible = true;

            // Add content to new window
            htmlLoader.load(new air.URLRequest('Projector.html'));

            // Make the window appear on the biggest screen
            htmlLoader.bounds = air.Screen.screens[1];

            // Make it full screen
            htmlLoader.stage.displayState = runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;

        }

    } else {

        // Show error that you need a projector screen
        alert('You need a projector screen');
    }       
}

我已经处理了检查是否有多个屏幕可用以及投影仪是否已经显示的部件。但需要找出最大的屏幕并确保当前窗口不会移动到它,而新的htmlLoader 会移动到它。

我该怎么做?

【问题讨论】:

    标签: javascript air


    【解决方案1】:

    寻找最大的屏幕:

    var largestScreen = null;
    for( var index = 0; index < Air.Screen.screens.length; ++index) {
        var currentScreen = Air.Screen.screens[index];
        if( largestScreen == null ){
            largestScreen = currentScreen;  
        }
        else{
            //Defining largest screen as biggest total area.
            var currentArea = currentScreen.bounds.width * currentScreen.bounds.height;
            var largestArea = largestScreen.bounds.width * largestScreen.bounds.height;
            if(currentArea > largestArea) {
                largestScreen = currentScreen;
            }
        }
    }
    

    在创建时需要将投影仪窗口设置为最大屏幕

    var htmlLoader = air.HTMLLoader.createRootWindow(false, options, false, largestScreen.bounds);  
    

    见参考:

    【讨论】:

    • 是 JavaScript 还是 ActionScript?我知道在 AIR 中,您可以在脚本标签中同时使用这两者……但想知道我是否可以仅使用 JavaScript 来做到这一点?谢谢。
    • 它们之间几乎没有区别。对 JS 来说唯一应该成为问题的就是第一行。见编辑。
    • 然后如何使投影仪屏幕显示在最大的屏幕上?当我这样做时:htmlLoader.bounds = largestScreen; 它抱怨它无法设置属性边界。谢谢。
    • 很酷 :) 标记为已回答并获得赏金。谢谢。想看看这个吗? stackoverflow.com/questions/24240491/…
    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    相关资源
    最近更新 更多