If you are used to using the ApplicationUpdaterUI class for providing the auto update feature for your AIR application, and have recently started to work on the new Native Process API in Adobe Air 2 beta for compiling into a Native app, you would realize that the auto update functionality just doesn’t work. This is because the ApplicationUpdaterUI is designed to work only for the default AIR applications (.air). If you want to provide auto update functionality for your executables (.exe), you need to rather use the ApplicationUpdater Class. You don’t have to modify the update.xml file. The only difference is since this is an executable, you can’t do an auto upgrade of the file. Rather, you will need to let the user download the file (if you are trying the update the .exe file). The most simplest way to do it is to capture the “UpdateStatus” event of the ApplicationUpdater and check if an update is available and then trigger a ‘navigateToURL”. Checking if there is a new version available can be done using the “StatusUpdateEvent.available” property. Here is the code that you can use.
private function checkForUpdate():void
{
appUpdater.updateURL=”<path>/update.xml”; // Server-side XML file describing update
appUpdater.addEventListener(UpdateEvent.INITIALIZED, onUpdate); // Once initialized, run onUpdate
appUpdater.addEventListener(StatusUpdateEvent.UPDATE_STATUS, onUpdateStatus);
appUpdater.addEventListener(ErrorEvent.ERROR, onError); // If something goes wrong, run onError
appUpdater.initialize(); // Initialize the update framework
}private function onError(e:UpdateEvent):void
{
Alert.show(e.toString());
}private function onUpdate(e:UpdateEvent):void
{
appUpdater.checkNow();
}private function onUpdateStatus(event:StatusUpdateEvent):void
{
if( event.available ) {
// set an information text for the user
application.updateInfo.label = “An updated version ” +
event.version + ” is available. Click here to download.”;
// or directly display a download prompt
var urlReq:URLRequest = new URLRequest(“<url to the executable>”);
navigateToURL(urlReq);
}
}
