Agile Developer, Berlin, Germany

18.03.2008

Using (Native)Windows with AIR

Filed under: air, flex, programming — pegolon @ 11:16

If you want to use windows in AIR with custom chrome (especially transparent) you have to consider some drawbacks. First you cannot use NativeWindow if you want to use Flex components from the mx.* namespace. There is a separate Window class in the AIR package which encapsulates a NativeWindow. To get your own content inside this window you can create a separate MXML file like this:

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Window xmlns:mx=”http://www.adobe.com/2006/mxml”
width=”200″ height=”100″
transparent=”true” systemChrome=”none” type=”normal”
showStatusBar=”false” showTitleBar=”false” showFlexChrome=”false”>
<PlaceYourContentHere/>
</mx:Window>

This will display a transparent window without any controls and header on the screen.

Whenever you want to create and display the window use:

var myWindow:MyWindow = new MyWindow
myWindow.open()

If you want to change the position of the window you have to use its nativeWindow property:

// Center window

myWindow.nativeWindow.x = (Capabilities.screenResolutionX – myWindow.width) / 2
myWindow.nativeWindow.y = (Capabilities.screenResolutionY – myWindow.height) / 2

I used to use the NativeWindow class for transparent windows since AIR beta 1. To get Flex-Containers in it I initialized them in the main application window, removed them there and added them to stage of the NativeWindow. This worked fine until I used controls like ComboBox or ColorPicker which relied on the PopupManager. The popup window didn’t occur until I found that it was opened in the main application window at the position of the initial component.

Blog at WordPress.com.