In a previous example, “Opening a new Window in Adobe AIR”, we saw how you could launch a new Flex Window container in Adobe AIR by creating a custom Window component and calling the open() method.

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.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2010/03/13/opening-a-new-nativewindow-in-adobe-air/ -->
<mx:WindowedApplication name="NativeWindowInitOptions_type_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        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"?>
<!-- http://airexamples.com/2010/03/13/opening-a-new-nativewindow-in-adobe-air/ -->
<mx:WindowedApplication name="NativeWindowInitOptions_type_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        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>
Tagged with:
 

2 Responses to Opening a new NativeWindow in Adobe AIR

  1. susrut mishra says:

    Thanks for the simple examples.

  2. Rich Gartland says:

    Hi, I’m doing something similar but have a problem I hope you can help with. I’m opening a new utility window and closing my original window (to avoid a taskbar slot being used up). I move my canvas over while creating the new window, so all my controls make it safely there. But later, I’d like to have a button that will resize the new window so I can expose some preference controls. So far I haven’t had any luck with trying to just resize the size using the equivalent of “win.height = …” code from your example. Ideas?

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Spam Protection by WP-SpamFree