Closing an Air app
Aug. 4, 2008 No Comments Posted under: Random
Whilst developing a little uploading application I found I need to store some application settings locally, in order to save the user entering them every time, and also that I needed one function to be called when the application closed, either via the OS (Apple+Q) or by a custom close button on my application.
To save information locally such as a user’s username and password you can use a Local Shared Object (LSO). This is a flash cookie, and much like a browser cookie, but managed by the Flash Player. Air seems to use the same LSO system, which also appear to be encrypted, however I would check up on this before storing anything highly sensitive.
The code is quite simple, and requires you to just set you local username and password variables to those in the LSO when the application loads. (see the code for more info).
In order to save them again you just set the LSO variables to your current username and password values. The advantage of a local desktop application is that there is a close / exit / quit event in AIR you can use, which isn’t the case on the web, as the flash player is ultimately controlled by the browser.
To set up a listner for this event you need to do the following:
NativeApplication.nativeApplication.addEventListener(Event.EXITING,onAppQuit);
You can then set up your saving in the onAppQuit function. If you want to manually close the application (custom chrome close button), then you just need to dispatch the close event, before closing the application, like so:
var ev:Event = new Event(Event.EXITING,false,true);
NativeApplication.nativeApplication.dispatchEvent(ev);
NativeApplication.nativeApplication.exit();
This entry was posted on Monday, August 4th, 2008 at 5:17 pm and is filed under Random. You can leave a comment and follow any responses to this entry through the RSS 2.0 feed.