Programmatically close an AIR application
Asked Answered
C

3

5

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

Consensual answered 17/2, 2011 at 16:47 Comment(0)
C
4

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();
Carlist answered 17/2, 2011 at 17:9 Comment(1)
When I first attempted this, I got a TypeError: Error #1009: Cannot access a property or method of a null object reference. This was because I had imported MX WindowedApplication rather than Spark. Your suggestion worked ( I used close() ). Thanks!Consensual
M
7

I know this question has been answered and accepted, but thought I'd share, I use.

stage.nativeWindow.close();
Malay answered 1/12, 2011 at 11:42 Comment(0)
C
4

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();
Carlist answered 17/2, 2011 at 17:9 Comment(1)
When I first attempted this, I got a TypeError: Error #1009: Cannot access a property or method of a null object reference. This was because I had imported MX WindowedApplication rather than Spark. Your suggestion worked ( I used close() ). Thanks!Consensual
E
1

Just give an answer here because I searched for a related question and was not able to find sth.

I wanted to do something similar and close an AIR application when the native close button of the document window (spark.components.Window) is pressed thought that the spark WindowedApplication container (the applications main window) is still active to hold and manage the native menu (at application startup it is also used to display a splash screen. It has to stay open since if it is closed the native menu won't show up or be accessible anymore so its visible property is just set to false).

My main problem was the window closing event. Registering it with ActionScript like

      this.addEventListener(Event.Closing, windowClosed);

does not work: No closing event was dispatched. The only way was to register an event handler directly in the s:Window element at start of the MXML file. I just throw in the closing attribute:

      closing="window1_closingHandler(event)"

The event was dispatched then and in window1_closingHandler-function I called

      NativeApplication.nativeApplication.exit();

That works for me and shuts down the whole application.

Esch answered 5/11, 2013 at 2:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.