Problem preventing Air applications from exiting1
In case you want to do some action before your application exits you should do the following:
NativeApplication.nativeApplication.addEventListener(Event.EXITING , windowExitingHandler);
And take whatever actions inside the method windowExitingHandler()
This method should have the following form:
private function windowExitingHandler(event:Event):void
{
event.preventDefault();
....
....
}
So, you must call, event.preventDefault(), to stop default exiting behaviour and introduce you own, then later you call
NativeApplication.nativeApplication.exit();
But take care, the exit() method, must be called after the windowExitingHandler() method is called.
An Example of wrong form:
private function windowExitingHandler(event:Event):void
{
event.preventDefault();
....
NativeApplication.nativeApplication.exit(); // WRONG
}
It won't close, and you've to do the following:
private function windowExitingHandler(event:Event):void
{
event.preventDefault();
....
setTimeout(onApplicationExitTimer, 100);
}
private function onApplicationExitTimer():void
{
NativeApplication.nativeApplication.exit();
}
Note:
I've experienced this on Mac, and not sure whether the same applies to other platforms.

1 Comments
10/19/10 at 13:28:04
Yep, I had something similar on Windows Vista, thanks!
Leave a Comment...