Adobe AIR Programming Unleashed: Working with Windows [con't]
Creating Windows Using mx.core.Window
The Adobe Flex mx.core.Window class essentially wraps NativeWindow and facilitates the addition of Adobe Flex content. As an Adobe Flex developer, you will find yourself using this class to create windows in most cases.
The steps to creating a Window differ slightly from NativeWindow:
- Create an instance of
Window. - Set
Windowproperties (optional—there are defaults). - Open the
Windowon the Screen.
NOTE
Rather than include full class path on each mention ofmx.core.Window, we use "Window" instead—capitalizing the "W."If we're just referring to the generic term "window," it is not capitalized.
Let's take a look at a simplistic example of instantiating a Window instance and opening it onscreen.
LISTING 5.2 Simple Example of Using mx.core.Window
Creating an Instance of Window
Using the Adobe Flex Window class, we create an instance:
Notice there is no NativeWindowInitOptions object passed into the constructor of Window. You can now set those same properties directly on the Window instance itself, as you will see demonstrated in the following section.
NOTE
Although a number of window properties can now be set after theWindowinstance has been created, certain properties still follow the rule of having to be applied before a window is opened onscreen, for example,systemChrome, type, and so on. After they're set, they cannot be changed.
Setting Window Properties
Using mx.core.Window differs from NativeWindow in that we can set all parameters after it
has been instantiated. The one exception is the NativeWindow property of Window; this is
not accessible until we open it onscreen.
To create a window using mx.core.Window, do the following:
NOTE
You can still use the same static variables from theNativeWindowclasses because they are essentially just resolving to strings.
As with NativeWindow, you have the same options to choose from with regard to both the chrome of the window instance and the window type. There are some differences in the results of these options which we'll take a closer look at now.
Chrome Options for mx.core.Window
Creating a Window with standard window chrome yields the same result as with NativeWindow. After all, mx.core.Window is essentially a NativeWindow primed to host Adobe Flex content. The only visual difference visually is the gray background, which represents the Adobe Flex content area (see Figure 5.5, Figure 5.6, Figure 5.7, Figure 5.8, Figure 5.9).
NOTE
Although the options for window types are the same asNativeWindow, a difference lies in how you deal with windows withsystemChromeset toNONE. WhensystemChromeis set toNONE, Adobe Flex displays its own system chrome. You can disable this by setting theshowFlexChromeproperty tofalseon yourWindowinstance.
At times, you will still need to access the underlying NativeWindow properties. For example, moving a window from one location onscreen to another requires setting the x and y coordinates of NativeWindow (see Listing 5.3). You won't find those properties on the parent mx.core.Window class.
LISTING 5.3 Referencing NativeWindow Properties When Using mx.core.Window
Opening a Window Onscreen
Finally, to open a Window onscreen, use the open() method. Although the Window defaults to "active," you have the option to change this via a Boolean passed in with the method call as follows:
Passing false into the open method will cause the Window to open but not make it active. In other words, give the window focus.

This chapter is an excerpt from the book, Adobe AIR Programming Unleashed by Stacy Young, Michael Givens and Dimitrios Gianninas, published by SAMS, ISBN 0672329719, copyright 2009 by Pearson Education, Inc. All rights reserved.
Original: March 2, 2009

Find a programming school near you