Replacing NativeWindow on mobile devices and TVs

The AIR NativeWindow API is a staple of desktop AIR applications, used to open multiple windows on the screen, each with its own stage. On mobile devices and TVs, the class is unsupported. So how does an application go about opening a window?

It doesn’t. On mobile devices and TVs, AIR applications can render only to the single available stage. The stage is automatically create and made visible when the application launches, and remains available until the application exits. In other words, it behaves essentially the same as the Stage does for Flash Player content.

Most code need concern itself only with the stage, and in this way can be made more portable between desktop, mobile, and TV deployment. For example, the stage directly provides information about its size. It also retains the ability to enter full-screen mode, and on mobile devices provides information about screen orientation.

If you have code that needs to check at runtime whether or not it can create new windows, simply check NativeWindow.isSupported.

10 Responses to Replacing NativeWindow on mobile devices and TVs

  1. Kyle says:

    Is that then the best way to determine if your actionscript code is running on a non-desktop device? (It would be also useful to know how to run a check that works on Flash Player too in order to be able to tell if you are running in the FP, on AIR desktop or on AIR for a device.)

    • Florian says:

      Good question, I’m interested to know too 😉

    • Oliver Goldman says:

      No, I would not recommend this as a check for a non-desktop device. In the future, some non-desktop devices, such as possibly TVs, may support NativeWindow, which would invalidate your check.

    • Oliver Goldman says:

      If your code uses AIR APIs, it won’t load into Flash Player, so in some sense that’s an easy thing to check!

  2. Veeck says:

    I am having trouble starting my mobile app on android in fullscreen mode since stage.nativeWindow.maximize() isnt supported there anymore. how can i achieve this now?

    • Oliver Goldman says:

      Use <fullScreen>true</fullScreen> in your application’s descriptor.

      By the way, NativeWindow.maximize() never put an application into full-screen mode, anyway. That’s accomplished via Stage.displayState, and that API is available on mobile.

  3. Seth says:

    I am trying to write a floating app that sits on the desktop, can be moved around, and re-sized. Without access to NativeWindow on the Android OS, is this possible with Actionscript and Adobe Air?

    • Oliver Goldman says:

      Not sure I follow the question. Android doesn’t have a desktop, so it isn’t clear to me how the lack of NativeWindow support on Android can be an issue.

  4. Nouman Hanif says:

    Hi Oliver,

    I am trying to package an Air 2.6 app for Android. It works fine on the desktop but when I try to run it using ‘adl’ it crashes on the loading screen with following stack trace

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at spark.components::WindowedApplication/initialize()[E:\dev\4.5.1\frameworks\projects\airspark\src\spark\components\]
    at main/initialize()
    at mx.managers.systemClasses::ChildManager/childAdded()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\systemClasses\]
    at mx.managers.systemClasses::ChildManager/initializeTopLevelWindow()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\systemClasses\]
    at mx.managers::SystemManager/initializeTopLevelWindow()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\]
    at mx.managers::SystemManager/[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\]
    at mx.managers::SystemManager/[E:\dev\4.5.1\frameworks\projects\framework\src\mx\managers\]
    at mx.preloaders::Preloader/timerHandler()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\preloaders\]
    at flash.utils::Timer/_timerDispatch()
    at flash.utils::Timer/tick()

    I have tried both with a custom preloader and without the result is same. I understand that nativewindow is not supported on mobileDevice profile and that is why it is getting a null reference in the initialize() method. I am not creating nativewindow objects at all it is the called implicitly when preloader code fires an event. Is there a way to not have preloader in the application? or can you suggest some other solution?