Monday, March 28, 2011

Working with windows in AIR: Part 2

In this tutorial we will learn how to actually create a window using AIR.

In the last part we've learned that we need to first set up the init options for our window before creating it.

Let's do that:

import flash.display.NativeWindowInitOptions;
import flash.display.NativeWindowType;
import flash.display.NativeWindowSystemChrome;

var myOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
myOptions.type = NativeWindowType.NORMAL;
myOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
myOptions.transparent = false;

We have the options. Next - creaing the window object.

import flash.display.NativeWindow;

var myWindow:NativeWindow = new NativeWindow(myOptions);
myWindow.width = 200;
myWindow.height = 200;

Now if you test your movie, you will see, that nothing happens. Why? Because we've created a window object, but have not activated it yet. But we can do that using the activate() method:

myWindow.activate();

If you test your application now - a new window opens as soon as the main does.



Here's the full code:

import flash.display.NativeWindowInitOptions;
import flash.display.NativeWindowType;
import flash.display.NativeWindow;
import flash.display.NativeWindowSystemChrome;

var myOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
myOptions.type = NativeWindowType.UTILITY;
myOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
myOptions.transparent = false;

var myWindow:NativeWindow = new NativeWindow(myOptions);
myWindow.width = 200;
myWindow.height = 200;

myWindow.activate();

But it's not much of a use if it is empty. We will learn how to add content to windows next time.

Thanks for reading!

Related:

Working with windows in AIR: Part 1
Working with windows in AIR: Part 3
Working with windows in AIR: Part 4
Working with windows in AIR: Part 5
Working with windows in AIR: Part 6
Working with windows in AIR: Part 7
Working with windows in AIR: Part 8
Working with windows in AIR: Part 9
Working with windows in AIR: Part 10
Working with windows in AIR: Part 11
Working with windows in AIR: Part 12

No comments:

Post a Comment