Search code examples
apache-flexairshutdownflex-spark

Programmatically close an AIR application


I would like to know the correct way to close an AIR application programmatically.

In my Spark WindowedApplication I have:

this.addEventListener( Event.CLOSING, shutdownApp );

and of course an implementation of the shutdownApp method (which basically tidies up temporary files).

This works fine for the top-right close button of the window. However I also have functionality which needs to shutdown the application. Within the code I have called:

NativeApplication.nativeApplication.exit();

However this doesn't trigger the Event.CLOSING method, and so my temporary files are not cleared up. Should I not be calling nativeApplication.exit ? If so, what should I call instead? I'd rather not have to call my shutdownApp method before the NativeApplication.exit() as this doesn't feel quite so elegant.

Can anyone shed any light on the correct way of doing this?

Thanks,

Phil


Solution

  • The documentation looks a bit ambiguous on this and I would have the same interpretation that you did. Did you try the close or exit methods on the WindowedApplication?

    Something like this, with FlexGlobals and topLevelApplication:

    (FlexGlobals.topLevelApplication as WindowedApplication).close();
    

    or

    (FlexGlobals.topLevelApplication as WindowedApplication).exit();