AS3, AIR, calling document class methods from a spawned window

I am creating an AIR application that spawns a new window, so there is a main application window and also another window. One can manipulate data in either window, and data is synchronized between the windows. So when I adjust data in the main window, I update the UI and data that’s in the secondary window.

The main window is a document class, and a class represents that which sits in the secondary window. I have updating methods in the secondary class so it’s easy to call them from the document class and have the magic happen.

However, if I change things in my secondary window, I update the UI there and the local copy of the underlying data, and need to tell the document class to do the same. This should be using a database or something so there is only ever one copy of the data both consume, but I was feeling lazy.

Anyway, after pounding my head for 30 minutes on how to access the main window and it’s document class from the class sitting in the spawned window of the AIR application, I finally figured it out.

import flash.desktop.*;
var who = NativeApplication.nativeApplication.openedWindows[0].stage.getChildAt(0);

And that does it. You could also just do the following too:

You can call methods in your main document class from a spawned window in an AIR application, send along whatever parameters you’d like, etc. This is a big time saver now that I figured this out. If this is common knowledge, I didn’t know about it.

Anyway, enjoy.

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.