| Subcribe via RSS

NativeWindowInitOptions – configure your AIR NativeWindow

August 6th, 2008 | No Comments | Posted in AIR, Actionscript 3.0, Tutorials

In a previous post I listed some code to create and activate a NativeWindow in an Actionscript AIR project without really explaining what was going on behind the scenes. In this post, I’ll explain a little more about the NativeWindowInitOptions class, and how you can control the appearance and behaviour of the NativeWindow that you create.

The code I used in the previous post was this:

var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
var mainWindow:NativeWindow = new NativeWindow(windowOptions);

Fairly obviously, the NativeWindow constructor accepts an instance of NativeWindowInitOptions as its first parameter. In the previous example, I’m not doing anything fancy with the NativeWindowInitOptions instance that I create, I just create a new instance of the class and pass it to the NativeWindow constructor. As a result, all the various properties will have their default values, and the NativeWindow will be totally default. How terribly dull. Here’s a list of properties of NativeWindowInitOptions that you can play with to control how the NativeWindow will look and behave when it’s created….

Continue reading NativeWindowInitOptions – configure your AIR NativeWindow »

Tags: , ,

Creating AIR projects with Actionscript

August 4th, 2008 | No Comments | Posted in AIR, Actionscript 3.0, Flex Builder

If you’re using Flex Builder 3, and you want to create an Actionscript project which will eventually deploy as an AIR application, you’ll quickly find that this option isn’t available when using the Actionscript Project Wizard. There are plenty of posts out there detailing a workaround (for example, see here).

I followed the workaround steps and it seemed to work OK, but when I first published my application… nothing happened. A little icon appeared in my dock, mysteriously titled adl (which I’ve since discovered stands for the AIR debug launcher), but no windows of Flash-based goodness appeared anywhere. After much digging around, I came across this entry in the Adobe Bug System and found the answer buried away in the comments.

When I’d previously created Flex-based AIR projects, I hadn’t really appreciated that the Flex framework was handling all of the window-creating shenanigans on my behalf. Just by making my root MXML tag a WindowedApplication, instead of a “normal” Application, the main AIR window was being created and activated automatically. When you’re not using the Flex framework, you have to do this stuff yourself.

As it turns out, the two most important classes involved in this process are flash.display.NativeWindow and flash.display.NativeWindowInitOptions. A NativeWindow is essentially the window you see on your desktop when you run an AIR application. This includes the menu bar (if any) and the system chrome (if any).

To successfully create and launch a window in AIR, you’ll need to create and activate a NativeWindow object, and then add your Document class (or some Sprite, at least) to that Window’s stage, accessible through the NativeWindow’s stage property. The code will look something like…

// create an instance of NativeWindowInitOptions to pass to the NativeWindow constructor
var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
// create the window
var mainWindow:NativeWindow = new NativeWindow(windowOptions);
// activate the window
mainWindow.activate();
// adds "this" to the stage of the Window we have created
mainWindow.stage.addChild(this);

This code will create and activate an AIR window with default options, and add someSprite to the stage of that Window. From then on, you can continue with your code just as you would in a traditional Flash application and all will work as expected.

I’ll post more about the NativeWindow and NativeWindowInitOptions classes at some point soon….

(Update: Check out this post for more information about the NativeWindowInitOptions class)

Tags: , ,