NativeApplication.nativeApplication.exit() doesn’t exit

31 sec read

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>



写作助手,把中式英语变成专业英文


Want to receive new post notification? 有新文章通知我

How much money did I make from an app?

Undoubtedly some people are very successful in making money by developing a smartphone app. Back in 2012 I developed an app called “Handbook of Brain” which is a collected resources of brain anatomy, function and diseases. I put the app i
Xu Cui
27 sec read

Handy programs to visualize NIRS data (2): plotTopoMap

Often you need to view the spatial pattern of activation as in the example below. plotTopoMap allows you to do that. It probably only works for Hitachi devices where the spatial relationship between channels are known. In the above example, the activ
Xu Cui
37 sec read

Flash 3D video demo

Racer Ostrova Zombie
Xu Cui
0 sec read

6 Replies to “NativeApplication.nativeApplication.exit() doesn’t exit”

  1. 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!

  2. 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

Leave a Reply

Your email address will not be published. Required fields are marked *