| Adobe AIR 1.1 |
|
|
AIR window basicsAIR provides an easy-to-use, cross-platform window API for creating native operating system windows using Flash®, Flex™, and HTML programming techniques. With AIR, you have a wide latitude in developing the appearance of your application. The windows you create can look like a standard desktop application, matching Apple style when run on the Mac, and conforming to Microsoft conventions when run on Windows. Or you can use the skinnable, extensible chrome provided by the Flex framework to establish your own style no matter where your application is run. You can even draw your own windows with vector and bitmap artwork with full support for transparency and alpha blending against the desktop. Tired of rectangular windows? Draw a round one. Windows in AIRAIR supports three distinct APIs for working with windows: the ActionScript-oriented NativeWindow class, the Flex framework mx:WindowedApplication and mx:Window classes, which “wrap” the NativeWindow class, and, in the HTML environment, the JavaScript Window class. ActionScript windowsWhen you create windows with the NativeWindow class, use the Flash Player stage and display list directly. To add a visual object to a NativeWindow, add the object to the display list of the window stage or to another display object on the stage. Flex Framework windowsThe Flex Framework defines its own window components. These components, mx:WindowedApplication and mx:Window, cannot be used outside the framework and thus cannot be used in HTML-based AIR applications. HTML windowsWhen you create HTML windows, you use HTML, CSS, and JavaScript to display content. To add a visual object to an HTML window, you add that content to the HTML DOM. HTML windows are a special category of NativeWindow. The AIR host defines a nativeWindow property in HTML windows that provides access to the underlying NativeWindow instance. You can use this property to access the NativeWindow properties, methods, and events described here. Note: The JavaScript
Window object also has methods for scripting the containing window,
such as moveTo() and close().
Where overlapping methods are available, you can use the method
that is most convenient.
The initial application windowThe first window of your application is automatically created for you by AIR. AIR sets the properties and content of the window using the parameters specified in the initialWindow element of the application descriptor file. If the root content is a SWF file, AIR creates a NativeWindow instance, loads the SWF file, and adds it to the window stage. If the root content is an HTML file, AIR creates an HTML window and loads the HTML. For more information about the window properties specified in the application descriptor, see The application descriptor file structure. Native window classesThe native window API contains the following classes:
Native window event flowNative windows dispatch events to notify interested components that an important change is about to occur or has already occurred. Many window-related events are dispatched in pairs. The first event warns that a change is about to happen. The second event announces that the change has been made. You can cancel a warning event, but not a notification event. The following sequence illustrates the flow of events that occurs when a user clicks the maximize button of a window:
Properties controlling native window style and behaviorThe following properties control the basic appearance and behavior of a window:
When you create a window, you set these properties on the NativeWindowInitOptions object passed to the window constructor. AIR reads the properties for the initial application window from the application descriptor. (Except the type property, which cannot be set in the application descriptor and is always set to normal.) The properties cannot be changed after window creation. Some settings of these properties are mutually incompatible: systemChrome cannot be set to standard when either transparent is true or type is lightweight. Window typesThe AIR window types combine chrome and visibility attributes of the native operating system to create three functional types of window. Use the constants defined in the NativeWindowType class to reference the type names in code. AIR provides the following window types:
Window chromeWindow chrome is the set of controls that allow users to manipulate a window in the desktop environment. Chrome elements include the title bar, title bar buttons, border, and resize grippers. System chromeYou can set the systemChrome property to standard or none. Choose standard system chrome to give your window the set of standard controls created and styled by the user’s operating system. Choose none to provide your own chrome for the window. Use the constants defined in the NativeWindowSystemChrome class to reference the system chrome settings in code. System chrome is managed by the system. Your application has no direct access to the controls themselves, but can react to the events dispatched when the controls are used. When you use standard chrome for a window, the transparent property must be set to false and the type property must be normal or utility. Window transparencyTo allow alpha blending of a window with the desktop or other windows, set the window transparent property to true. The transparent property must be set before the window is created and cannot be changed. A transparent window has no default background. Any window area not containing an object drawn by the application is invisible. If a displayed object has an alpha setting of less than one, then anything below the object shows through, including other display objects in the same window, other windows, and the desktop. Rendering large alpha-blended areas can be slow, so the effect should be used conservatively. Transparent windows are useful when you want to create applications with borders that are irregular in shape or that “fade out” or appear to be invisible. Transparency cannot be used with windows that have system chrome. In addition, SWF and PDF content in HTML does not display in transparent windows. For more information, see Considerations when loading SWF or PDF content in an HTML page. On some operating systems, transparency might not be supported because of hardware or software configuration, or user display options. When transparency is not supported, the application is composited against a black background. In these cases, any completely transparent areas of the application display as an opaque black. The static NativeWindow.supportsTransparency property reports whether window transparency is available. If this property tests false, for example, you could display a warning dialog to the user, or display a fallback, rectangular, non-transparent user interface. Note that transparency is always supported by the Mac and Windows operating systems. Support on Linux operating systems requires a compositing window manager, but can also be unavailable because of user display options or hardware configuration. Transparency in an HTML application windowBy default the background of HTML content displayed in HTML windows and HTMLLoader objects is opaque, event if the containing window is transparent. To turn off the default background displayed for HTML content, set the paintsDefaultBackground property to false. The following example creates an HTMLLoader and turns off the default background: var html:HTMLLoader = new HTMLLoader(); html.paintsDefaultBackground = false; This example uses JavaScript to turn off the default background of an HTML window: window.htmlLoader.paintsDefaultBackground = false; If an element in the HTML document sets a background color, the background of that element is not transparent. Setting a partial transparency (or opacity) value is not supported. However, you can use a transparent PNG-format graphic as the background for a page or a page element to achieve a similar visual effect. A visual window catalogThe following table illustrates the visual effects of different combinations of window property settings on the Mac OS X and Windows operating systems:
Note: The
following system chrome elements are not supported by AIR: the OS
X Toolbar, the OS X Proxy Icon, Windows title bar icons, and alternate
system chrome.
|