Opening a new NativeWindow in Adobe AIR
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>
- Share this:
2 Responses to Opening a new NativeWindow in Adobe AIR
Leave a Reply Cancel reply
- http://get.adobe.com/air/
- Platform ActionScript Language Reference
Recent Posts
- Detecting the number of screens on a users system in Adobe AIR
- Opening a new NativeWindow in Adobe AIR
- Detecting the line-ending character sequence used by the host operating system in Adobe AIR
- Displaying a custom title bar icon in a WindowedApplication container in Adobe AIR
- Setting a custom text style on the status bar on a WindowedApplication container in Adobe AIR
- Keeping a WindowedApplication on top of other windows in Adobe AIR
- Specifying whether a new Window is focused in Adobe AIR
- Opening a new Window in Adobe AIR
- Setting the file size display mode in the Flex FileSystemDataGrid control in Adobe AIR
- Sorting the FileSystemDataGrid control by date in Adobe AIR
Archives
- March 2010 (10)
- February 2009 (3)
- January 2009 (6)
- December 2008 (44)
Thanks for the simple examples.
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?