| Subcribe via RSS

NativeWindow – using AIR windows with Actionscript (part 3 of 3)

August 10th, 2008 | 3 Comments | Posted in AIR, Actionscript 3.0, Tutorials

In the first part of this post I covered each public property exposed by an instance of NativeWindow, before continuing to look at each public method in part two. In this final part of the series I’ll go through each of the different events dispatched by a NativeWindow during its lifetime.

Event.ACTIVATE

This event is sent out when the window is activated. The event doesn’t go through a capture phase, and it won’t bubble up the Display List. Some examples of when your window may dispatch this event include:

  • When the NativeWindow is first created and activated
  • When your application contains multiple NativeWindows and the user clicks on a window which previously was not the active window, giving it focus and bringing it to the front, the window will dispatch Event.ACTIVATE
  • When you switch to another running application elsewhere on the system (an AIR application, or otherwise) and then switch back to this window, the event will be dispatched

Continue reading NativeWindow – using AIR windows with Actionscript (part 3 of 3) »

Tags: , ,

NativeWindow – using AIR windows with Actionscript (part 2 of 3)

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

In the previous post I listed the public properties exposed by an instance of NativeWindow. In this post, I’ll be going through NativeWindow’s public methods. The third and final part of this series will explain the Events dispatched by a NativeWindow during its lifetime.

Once a NativeWindow has been created, you can call methods to move, resize, reposition, activate and close the window. All these methods are fairly simple, with the odd gotcha thrown in for good measure. So, here’s a description of each of these methods…

Continue reading NativeWindow – using AIR windows with Actionscript (part 2 of 3) »

Tags: , ,

NativeWindow – using AIR windows with Actionscript (part 1 of 3)

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

In a previous post I described how to create and activate an application window when creating an Actionscript AIR project in Flex Builder 3. I then went on to describe in a little more detail the various properties of the NativeWindowInitOptions class, and how setting some or all of these properties can affect the style and behaviour of the window that will be created. I guess the final step is to describe how to work with the window once it has been created, starting with an explanation of the flash.display.NativeWindow class. There’s quite a bit of functionality contained within the class, so I’ll break this post up into three. Part 1 will describe the properties of a NativeWindow, part 2 will list the public methods and finally part 3 will discuss the events dispatched by the Window throughout its lifetime.

As previously mentioned, an application window is created and displayed in Adobe AIR by creating a new instance of the NativeWindow class, and then calling this instance’s activate method. Content is added to the window by adding DisplayObjects to the stage property of the NativeWindow instance.

Here are descriptions of each of the NativeWindow’s public properties…

Continue reading NativeWindow – using AIR windows with Actionscript (part 1 of 3) »

Tags: , ,

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: , ,