ScreenDemo.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
height="100%" width="100%" backgroundColor="#323232" creationComplete="init()" remove="removePopups();">
<mx:Script>
<![CDATA[
import mx.controls.Button;
import flash.display.Screen;
import mx.controls.Alert;
private var winNumber:int = 0;
private var myWindows:Array = new Array();
private function init():void {
var mainScreen:Screen = Screen.mainScreen; // Main screen as defined by OS (see docs)
var screenArray:Array = Screen.screens;
message.text = "Screens found:\n";
var virtualBounds:Rectangle = new Rectangle();
for each(var screen:Screen in screenArray) {
message.text += "\tScreen Size: " + screen.bounds.width + "x" + screen.bounds.height + "\n";
message.text += "\tVisible Bounds (excludes taskbar/menubar/dock):" + screen.visibleBounds.width + "x" + screen.visibleBounds.height + "\n";
message.text += "\tColors: " + screen.colorDepth.toString() + " bit\n\n";
// Calculate virtual screen size (combines monitor resolutions)
if(virtualBounds.left > screen.bounds.left) {virtualBounds.left = screen.bounds.left;}
if(virtualBounds.right < screen.bounds.right) {virtualBounds.right = screen.bounds.right;}
if(virtualBounds.top > screen.bounds.top) {virtualBounds.top = screen.bounds.top;}
if(virtualBounds.bottom < screen.bounds.bottom) {virtualBounds.bottom = screen.bounds.bottom;}
// Determine the center point of each screen
var centerX:int = screen.bounds.right - screen.bounds.width + (screen.bounds.width / 2);
var centerY:int = screen.bounds.bottom - screen.bounds.height + (screen.bounds.height / 2);
// Open a window in the center of each screen
myWindows[winNumber] = new DemoWindow();
myWindows[winNumber].open();
myWindows[winNumber].setMsg("Screen Size: " + screen.bounds.width + "x" + screen.bounds.height + " (" + screen.colorDepth.toString() + " bit)");
myWindows[winNumber].move(centerX - (myWindows[winNumber].width)/2, centerY - (myWindows[winNumber].height)/2);
++winNumber;
}
message.text += "Virtual Screen Size: " + virtualBounds.width + "x" + virtualBounds.height + "\n";
}
private function removePopups():void {
var i:int;
for (i = 0; i<winNumber; ++i) myWindows[i].close();
}
]]>
</mx:Script>
<mx:TextArea id="message" borderThickness="0" color="white" backgroundColor="#323232" width="100%" height="100%"/>
</mx:WindowedApplication>
DemoWindow.mxml (the popup itself):
<?xml version="1.0" encoding="utf-8"?>
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle"
horizontalAlign="center" backgroundColor="#3333FF" width="250" height="90"
showStatusBar="false" showTitleBar="false" showGripper="false" borderStyle="none">
<mx:Script>
<![CDATA[
public function setMsg(msgIn:String):void {
msg.text = msgIn;
}
]]>
</mx:Script>
<mx:Label id="msg" fontWeight="bold" color="white" />
<mx:Button id="winButton" label="Close" click="this.close()"/>
</mx:Window>
This sample is also available in Tour de Flex