Adobe AIR Auto Update

Adding an auto update to your AIR program isn't really as hard as some how-to's online make it seem. Let me put a few code blocks here that will help you go understand how this can be accomplished.

First off.. create a function to create the auto-update object and add listeners.. then call the update.. like so:


import air.update.ApplicationUpdaterUI;
import air.update.events.UpdateEvent;

import flash.events.ErrorEvent;
import flash.filesystem.File;

import mx.controls.Alert;

private var appUpdater:ApplicationUpdaterUI;

public function checkForUpdate():void
{
trace("checking for new application");

appUpdater = new ApplicationUpdaterUI();
appUpdater.configurationFile =
File.applicationDirectory.resolvePath("assets/cfg/update_config.xml");
appUpdater.addEventListener(UpdateEvent.INITIALIZED, updaterInitialized);
appUpdater.addEventListener(ErrorEvent.ERROR,onError);
appUpdater.initialize();
}

private function onError(event:ErrorEvent):void
{
Alert.show(event.toString());
}

private function updaterInitialized(e:UpdateEvent):void
{
trace("checking for updates");
appUpdater.checkNow();
}

Once you have that in place you have to have a few xml files to reference. The first is clientside that the air client references when it loads. This file tells the air app the location on the web it needs to go to in order to find an xml file with update information. In our above code we called it update_config.xml. This file was put in our assets/cfg folder. You can find more documentation online about the different variables this config file takes.. but this is a base version. This file would look something like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://ns.adobe.com/air/framework/update/configuration/1.0">
<url>http://pathtoserver.com/updates/update_descriptor.xml</url>
<delay>1</delay>
<defaultUI>
<dialog name="checkForUpdate" visible="false" />
<dialog name="downloadUpdate" visible="true" />
<dialog name="downloadProgress" visible="true" />
<dialog name="installUpdate" visible="true" />
</defaultUI>
</configuration>

Alternatively.. you can just put the config options inline instead of loading an xml file.. like so:

...
appUpdater.addEventListener(ErrorEvent.ERROR,onError);
appUpdater.delay = 1;
appUpdater.updateURL = "http://localhost/updater/update.xml";
appUpdater.isCheckForUpdateVisible = false;
appUpdater.isDownloadUpdateVisible = true;
appUpdater.isDownloadProgressVisible = true;
appUpdater.isInstallUpdateVisible = true;
appUpdater.initialize();

Lastly the file that is loaded by air from the web is referenced in this config xml as update_descriptor.xml. This file looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<update xmlns="http://ns.adobe.com/air/framework/update/description/1.0">
<version>version of your app.. either a number or letter sequence..
like 1.2.3</version>
<url>http://pathtoserver.com/application.air</url>
<description>This will show up in the update dialog.</description>
</update>

I think the tags in this xml file make it somewhat easy to understand what each piece does. I hope this helps clear things up because for me it took a little time to put all the pieces together.

You need to make sure the version number in your air application matches the version in your update_descriptor.xml when you deploy an update.

Happy Flashing!