UpdateManager
| By Rich Tretola | February 13, 2008 | |
| 13,164 views |
AIR applications are out in the world with no connection back to home unless you actively code your application to check in from time to time to say hello is there a new version of me available? I have been working on an easy system for keeping AIR applications up to date and I have come up with an UpdateManager that simplifies this process.
The constructor of the UpdateManager class can also accept one optional argument.
Constructor arguments
versionURL:String – URL of the version.xml file to check *required
autoCheck:Boolean – whether or not to automatically check for updates, defaults to true
properties
currentVersion:String – bindable property showing the current version of the application
methods
checkForUpdate(showAlert:Boolean=true) – will check for updates when called
showAlert:Boolean – whether or not to show user the Alert when no update is available, defaults to true
How it works
Upon load of the application the UpdateManager examines the applicationDescriptor property of the NativeApplication.nativeApplication to determine the version of the installed application. This is then stored in the currentVersion property.
If autoCheck is true it will load in this XML file, parses it and compares the version property of the XML file with the version that was parsed from the applicationDescriptor. If there is a difference, and the forceUpdate property of the version.xml file is true, the application is automatically updated. If there is a difference and forceUpdate is false, the user is alerted of the available update, given a description of the update, and given the option to update their application The UpdateManager will then perform the update using the File and FileStream classes to download and write the new air file to disk and then the Updater class to complete the update.
The UpdateManager also contains a checkForUpdate() method which will allow your application to provide a way for its user to manually trigger a check for an update. To use the UpdateManager, you will simply need to create an instance of the UpdateManager and pass in the URL of the version.xml file. You may also pass in the optional second argument.
Basic sample initializing the UpdateManager:
1 | private var um:UpdateManager = new UpdateManager("http://www.mydomain.com/appname/version.xml"); |
Update is available:

No update available:

Required Update:

Here is a full sample using the UpdateManager. In this sample, the application will only check for updates when the user clicks the “Test For Update” button.
1 2 3 4 5 6 7 8 9 10 11 | <?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ import com.everythingflex.air.managers.UpdateManager; private var um:UpdateManager = new UpdateManager("http://www.yourdomain.com/AIR/UMTest/version.xml",false); ]]> </mx:Script> <mx:Button click="um.checkForUpdate()" label="Test for Update" horizontalCenter="0" verticalCenter="0"/> </mx:WindowedApplication> |
The version.xml file is required and needs to be stored at the URL that was supplied as the versionURL within the UpdateManager’s constructor. It must follow this exact format.
XML attributes for currentVersion XML file
version:String – newest available version information
downloadLocation:String – URL to the air file of the newest available version
forceUpdate:Boolean – if true the update dialog will alert the user of a required update, if the user chooses not to update, the application will close, if false user will get the option to update
message:String – message shown to the user in the Alert window when a new version is available
Sample version.xml file:
1 2 3 4 5 | <?xml version="1.0" encoding="ISO-8859-1"?> <currentVersion version=".2" downloadLocation="http://www.yourdomain.com/AIR/UMTest/UM.air" forceUpdate="false" message="Added new features"/> |








