我在HTML / JavaScript中构建一个Adobe 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
将其移动到。
我该怎么做?
答案 0 :(得分: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);
参见参考资料: