AIR Tutorials – How to open a NativeWindow in Adobe AIR?

June 13, 2010 at 8:16 pm Leave a comment

The following example shows how you can launch a new “normal” or “utility” NativeWindow container in Adobe AIR by creating a NativeWindowInitOptions object, specifying the type property to one of the static constants in the NativeWindowType class, and passing the NativeWindowInitOptions object to the NativeWindow constructor.

And from the documentation:

Constants for the valid values of this property are defined in the NativeWindowType class:

* NativeWindowType.NORMAL — A typical window. Normal windows use full-size chrome and appear on the Windows task bar and the Mac OS X window menu.
* NativeWindowType.UTILITY — A tool palette. Utility windows use a slimmer version of the system chrome and do not appear on the Windows task bar and the Mac OS-X window menu.

* NativeWindowType.LIGHTWEIGHT — lightweight windows cannot have system chrome and do not appear on the Windows task bar and the Mac OS X window menu. In addition, lightweight windows do not have the System (Alt-Space) menu on Windows. Lightweight windows are suitable for notification bubbles and controls such as combo-boxes that open a short-lived display area. When the lightweight type is used, systemChrome must be set to none.

Normal Window

Utility Window

<?xml version="1.0" encoding="utf-8"?>

<mx:WindowedApplication name="NativeWindowInitOptions_type_test"
xmlns:mx="http://www.adobe.com/2006/mxml&quot;
layout="vertical">

<mx:Script>
<![CDATA[
private var opts:NativeWindowInitOptions;
private var win:NativeWindow;

private function btn_click():void {
opts = new NativeWindowInitOptions();
opts.type = cBox.selectedItem.toString();

win = new NativeWindow(opts);
win.title = opts.type;
win.width = 320;
win.height = 200;
win.activate();
}
]]>
</mx:Script>

<mx:ApplicationControlBar dock="true">
<mx:Label text="type:" />
<mx:ComboBox id="cBox" dataProvider="[normal,utility]" />
</mx:ApplicationControlBar>

<mx:Button label="Launch {cBox.selectedItem} window"
click="btn_click();" />

</mx:WindowedApplication>

Due to popular demand, here is the “same” example in a more ActionScript friendly format:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication name="NativeWindowInitOptions_type_test"
xmlns:mx="http://www.adobe.com/2006/mxml&quot;
layout="vertical"
initialize="init();">

<mx:Script>
<![CDATA[
import mx.containers.ApplicationControlBar;
import mx.controls.Button;
import mx.controls.ComboBox;
import mx.controls.Label;

private var opts:NativeWindowInitOptions;
private var win:NativeWindow;
private var cBox:ComboBox;

private function init():void {
var arr:Array = [NativeWindowType.NORMAL, NativeWindowType.UTILITY];

var lbl:Label = new Label();
lbl.text = "type:";

cBox = new ComboBox();
cBox.dataProvider = arr;

var appControlBar:ApplicationControlBar = new ApplicationControlBar();
appControlBar.dock = true;
appControlBar.addChild(lbl);
appControlBar.addChild(cBox);
addChildAt(appControlBar, 0);

var btn:Button = new Button();
btn.label = "Launch window";
btn.addEventListener(MouseEvent.CLICK, btn_click);
addChild(btn);
}

private function btn_click(evt:MouseEvent):void {
opts = new NativeWindowInitOptions();
opts.type = cBox.selectedItem.toString();

win = new NativeWindow(opts);
win.title = opts.type;
win.width = 320;
win.height = 200;
win.activate();
}
]]>
</mx:Script>

</mx:WindowedApplication>

Entry filed under: AIR.

Flex Tutorials – Module Based Application In Flex 3.0 AIR Tutorials – How to keep WindowApplication on top of the applications in AIR

Leave a comment

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

June 2010
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
282930  

Most Recent Posts