我正在用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
窗口会移动到它。
我该怎么做?
查找最大屏幕:
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);
参见参考文献:
- flash.display.NativeWindow
- flash.html.HTMLLoader
- flash.display.Screen