屏幕
根据AIR screen API可以获得系统桌面显示屏幕的信息。
屏幕简介
screen API包含一个简单类,Screen,获得系统屏幕信息和屏幕的详细描述。
计算机系统可能有多个监视器或显示设备,这样对应的多个桌面屏幕排列在虚拟空间上。AIR Screen类提供了关于屏幕信息,如果有多个监视器映射到同一个屏幕上,那只有一个屏幕可显示,如果屏幕的尺寸大于监视器显示范围,没有办法确定是哪一部分处于可视状态。
一个屏幕表示一个独立的桌面显示区域,被描述为虚拟桌面的一个矩形区域,屏幕左上角为初始坐标,单位为像素。

上面的屏幕排列中,虚拟桌面上有两个屏幕,主屏幕(#1)的左上角坐标总是(0,0),如果屏幕排列设置屏幕#2作为主屏幕,则屏幕#1的坐标将为负坐标,一般指屏幕的可使用边界不包括菜单栏,任务栏。
枚举屏幕
通过下列屏幕方法和属性枚举虚拟桌面上的屏幕:
Screen.screens
数组对象,表示可用的屏幕,注意数组的元素顺序不是有效的。
Screen.mainScreen
表示代表主屏幕的屏幕对象,在Mac OS X系统中,主屏幕为显示菜单栏的所在屏幕,在Windows中为系统指定的主屏幕。
Screen.getScreensForRectangle()
通过指定的区域获得屏幕对象数组,该矩形区域作为参数传递给该方法,如果没有屏幕在范围内则返回空数组。
这个例子使用screen API通过方向键在多个屏幕中移动窗体。
package { 
import flash.display.Sprite; 
import flash.display.Screen; 
import flash.events.KeyboardEvent; 
import flash.ui.Keyboard; 
import flash.display.StageAlign; 
import flash.display.StageScaleMode; 

public class ScreenExample extends Sprite 
{ 
public function ScreenExample() 
{ 
stage.align = StageAlign.TOP_LEFT; 
stage.scaleMode = StageScaleMode.NO_SCALE; 
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKey); 
} 

private function onKey(event:KeyboardEvent):void{ 
if(Screen.screens.length > 1){ 
switch(event.keyCode){ 
case Keyboard.LEFT : 
moveLeft(); 
break; 
case Keyboard.RIGHT : 
moveRight(); 
break; 
case Keyboard.UP : 
moveUp(); 
break; 
case Keyboard.DOWN : 
moveDown(); 
break; 
} 
} 
} 

private function moveLeft():void{ 
var currentScreen = getCurrentScreen(); 
var left:Array = Screen.screens; 
left.sort(sortHorizontal); 
for(var i:int = 0; i < left.length - 1; i++){ 
if(left[i].bounds.left < stage.nativeWindow.bounds.left){ 
stage.nativeWindow.x += 
left[i].bounds.left - currentScreen.bounds.left; 
stage.nativeWindow.y += left[i].bounds.top - currentScreen.bounds.top; 
} 
} 
} 

private function moveRight():void{ 
var currentScreen:Screen = getCurrentScreen(); 
var left:Array = Screen.screens; 
left.sort(sortHorizontal); 
for(var i:int = left.length - 1; i > 0; i--){ 
if(left[i].bounds.left > stage.nativeWindow.bounds.left){ 
stage.nativeWindow.x += 
left[i].bounds.left - currentScreen.bounds.left; 
stage.nativeWindow.y += left[i].bounds.top - currentScreen.bounds.top; 
} 
} 
} 

private function moveUp():void{ 
var currentScreen:Screen = getCurrentScreen(); 
var top:Array = Screen.screens; 
top.sort(sortVertical); 
for(var i:int = 0; i < top.length - 1; i++){ 
if(top[i].bounds.top < stage.nativeWindow.bounds.top){ 
stage.nativeWindow.x += top[i].bounds.left - currentScreen.bounds.left; 
stage.nativeWindow.y += top[i].bounds.top - currentScreen.bounds.top; 
break; 
} 
} 
} 

private function moveDown():void{ 
var currentScreen:Screen = getCurrentScreen(); 

var top:Array = Screen.screens; 
top.sort(sortVertical); 
for(var i:int = top.length - 1; i > 0; i--){ 
if(top[i].bounds.top > stage.nativeWindow.bounds.top){ 
stage.nativeWindow.x += top[i].bounds.left - currentScreen.bounds.left; 
stage.nativeWindow.y += top[i].bounds.top - currentScreen.bounds.top; 
break; 
} 
} 
} 

private function sortHorizontal(a:Screen,b:Screen):int{ 
if (a.bounds.left > b.bounds.left){ 
return 1; 
} else if (a.bounds.left < b.bounds.left){ 
return -1; 
} else {return 0;} 
} 

private function sortVertical(a:Screen,b:Screen):int{ 
if (a.bounds.top > b.bounds.top){ 
return 1; 
} else if (a.bounds.top < b.bounds.top){ 
return -1; 
} else {return 0;} 
} 

private function getCurrentScreen():Screen{ 
var current:Screen; 
var screens:Array = Screen.getScreensForRectangle(stage.nativeWindow.bounds); 
(screens.length > 0) ? current = screens[0] : current = Screen.mainScreen; 
return current; 
} 
} 
}
AIR Screen API详解

2947

被折叠的 条评论
为什么被折叠?



