Sunday, May 15, 2011

HTML in AIR: Part 5

Today we will learn about the createRootWindow() method of a HTMLLoader object.

Sometimes it is needed to open your HTML content in a new AIR window, and it is possible to tell AIR to do that and automatically add scroll bars to it, all possible with one method. And that is the static HTMLLoader method called createRootWindow().

This method creates a new HTMLLoader function and returns it. It creates a new AIR window and puts this HTMLLoader object into it. All you have to do after that is call the load() or loadString() method to load the content into the object.

As I said before, the method is static. This means we call the function like this:

var myHtml:HTMLLoader = HTMLLoader.createRootWindow();

Then we call the load() or loadString() method like we usually do with HTMLoader objects:

myHtml.load(new URLRequest(""));

You aren't obliged to pass any parameters to the function, but, you can. And these optional parameters are: visible, WindowInitOptions, scrollBarsVisible and bounds.

The visible parameter is a boolean value that determines whether the window is visible on start.

The WindowInitOptions is a NativeWindowInitOptions object. This is where we can pass options for the new AIR window.

The scrollBarsVisible parameter is a boolean value, which displays the scroll bars if it is set to true, and hides them if it is set to false.

The bounds parameter is a Rectangle object, which you can use to set the coordinates and size of your new window.

So, if you use the parameters, your code could look like this:

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

var myHtml:HTMLLoader = HTMLLoader.createRootWindow(true, myOptions, true, new Rectangle(50, 50, 800, 600));
myHtml.load(new URLRequest(""));

And that's how you use it. If you want to learn more about windows in AIR, check out my tutorials about NativeWindows.

Thanks for reading!


HTML in AIR: Part 1
HTML in AIR: Part 2
HTML in AIR: Part 3
HTML in AIR: Part 4
HTML in AIR: Part 6
HTML in AIR: Part 7
HTML in AIR: Part 8
HTML in AIR: Part 9
HTML in AIR: Part 10
HTML in AIR: Part 11
HTML in AIR: Part 12
HTML in AIR: Part 13
HTML in AIR: Part 14
HTML in AIR: Part 15
HTML in AIR: Part 16
HTML in AIR: Part 17


Ezz said...

thanks for your efforts
keep up the good work

Anonymous said...


Post a Comment