AIR: Window vs. NativeWindow

This one threw me for a loop.  So I’ve been using the flash.display.NativeWindow class to create new windows in AIR (via Flex) since the beta releases.  Historically, this has been a pain when you want to add MXML components to the native window as addChild() does not work with the NativeWindow class unless that child object is first added to some other MXML container.  Somewhat of a pain, in practice.

Apparently, the mx.core.Window class was added in AIR 1.0 to resolve this problem.  The Window class is a sort of UIComponent wrapper for a NativeWindow.  This allows you to add other components directly to the Window through addChild().  Though in my particular situation, it simply caused more issues as the Window component class seems to inherit the properties of your initial application window somewhat- therefore, if you are trying to generate chromeless, transparent windows in a standard application interface… you can’t.

In the end, I find flash.display.NativeWindow a lot more flexible than mx.core.Window… and it is most likely a bit lighter in terms of the codebase as well.  The Window class may be a good option in some situations, and it’s really good to know that it exists.  You can never have too many options!

7 thoughts on “AIR: Window vs. NativeWindow”

  1. Hi Joseph,

    I was just having trouble adding a UIComponent to a NativeWindow, and it seems true that it doesn’t work. What exactly do you mean with “unless that child object is first added to some other MXML container.” I thought you meant something like first addng a Canvas and then adding your UICompenent to that Canvas. But that does not work either.

    Do you have a simple example in code?

    Thanks a lot.

  2. James Thompson

    I’m afraid that won’t do the job – the problem is that the NativeWindow does not create a system manager in the way that the Window class does. You can do a hack to add and remove an object to force it to render, but you’ll get a number of “object is null” errors if you try and use anything but the most basic controls.

    The best way around this is to sub-class the NativeWIndow so it creates a system manager before you add any controls to it.

    There’s a sample that explains how to do it here:

    http://www.ben-morris.com/howto-add-flex-mx-controls-to-a-nativewindow-for-adobe-air

  3. Thank you so much James Thompson for sharing such informative link. I was stuck in adding MXML canvas component to Native window, and could not catch the issue. This link solved my issue…
    wish you all the best

Leave a Comment

Your email address will not be published. Required fields are marked *