If your AIR application needs to do something (e.g. saving some settings) before quitting, you may listen to the Event.EXITING event, and then preventDefault(), then do something, and finally call NativeApplication.nativeApplication.exit() to quit. But, if you call NativeApplication.nativeApplication.exit() too quickly (e.g. call it right after preventDefault())), your application won’t exit. The solution is to wait some time (e.g. 100 ms) and call this function.
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init();"> <mx:Script> <![CDATA[ private function init():void { NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExiting); } private function onExiting(e:Event):void { e.preventDefault(); var t:Timer = new Timer(100); t.addEventListener(TimerEvent.TIMER, onTimer); t.start(); } private function onTimer(e:TimerEvent):void { NativeApplication.nativeApplication.exit(); } ]]> </mx:Script> </mx:WindowedApplication>
It’s not just Mac – I was having an issue on Windows where the app would disappear, but you had to go into Task Manager and “End Process” to truly shut it down. Adding a pause of 100ms fixed it. Thanks for this post!
Glad to hear it helps.
It works. Thank you.
Phew…thanks a ton man…Spent more than 2 days trying to figure out why it would not quit on a mac … Finally it worked using the timer technique…Thank you so much
Thanks a lot..!
That what I was looking for!
Even after 4 years still work perfectly on windows.
Thanks for help!