Close all opened Windows in an AIR app

Try this if you want to close all of the Windows that have been created in an AIR app.

NativeApplication.nativeApplication.addEventListener( Event.EXITING, exitApp );

private function exitApp( e:Event ):void {
	e.preventDefault();
	for ( var i:int = NativeApplication.nativeApplication.openedWindows.length - 1; i >= 0; --i ) {
		NativeWindow( NativeApplication.nativeApplication.openedWindows[i] ).close();
	}
}

If you create an AIR app that opens chromeless Windows that don’t have any close buttons then you’re kind of screwed if you close the main window and just leave the spawned windows hanging. You won’t be able to publish again until all the windows are closed. At least that’s how it works on WinXP.
I have noticed that when testing an AIR app from Flex Builder it shows up as adl.exe in the Windows Task Manager. So ending that process will close your app, and any windows it spawned.