« AIR 1.1 and Apprise 1.5 | Main | Share stories right from your news reader »
July 2, 2008
Closing all your application windows in AIR
Here's a little snippet of code I sometimes use in AIR applications to make sure all windows close when the main application window closes. I usually put it in the main application MXML file (the main window of the application). It stops the main window from closing, and closes any other opened application windows first in the opposite order in which they were opened (more recent windows first). Without code like this, if you have any other windows open, even little utility windows, and your main application window is closed, your application will not exit, even if NativeApplication.autoExit is set to true.
this.nativeWindow.addEventListener(Event.CLOSING,
function(e:Event):void
{
e.preventDefault();
for (var i:int = NativeApplication.nativeApplication.openedWindows.length - 1; i >= 0; --i)
{
NativeWindow(NativeApplication.nativeApplication.openedWindows[i]).close();
}
});
Posted by cantrell at July 2, 2008 9:28 AM
Comments
I'm kinda surprised there isn't some built in API for this. Maybe a good idea for the next point release?
Posted by: Raymond Camden at July 2, 2008 11:39 AM
If you want wo close all the windows,
why not invoke the NativeApplication.nativeApplication.exit() method?
Posted by: paravoice at July 3, 2008 9:07 PM
That works too, but then closing and close events are not dispatched to your windows. I like to use this code because it gives me the opportunity to hook into the closing event in any opened window if I ever need to (to prompt for save, for instance).
Christian
Posted by: Christian Cantrell at July 15, 2008 9:14 AM
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).