简体   繁体   中英

Show Window on largest screen using Adobe AIR

I'm building an Adobe AIR application in HTML/JavaScript that will use two windows, once of which will be display on the largest screen available (if available).

The code is as follows:

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

I've handled the parts checking if more than one screen is available and if the projector is already being displayed. But need to find out which is the biggest screen and make sure that the current window DOES not move to it, and the new htmlLoader one DOES move it to.

How can I do this?

Finding the largest screen:

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

Setting the projector window to the largest screen needs to happen on creation

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

See reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM