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>
Receive email notification via email 博客有新内容通知我
Don't want to miss new papers in your field? Check out Stork we developed: ![]() |
专注医学生物类的论文润色 联系他们请用优惠码 STORK4,他们会给你折扣。 |
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!