Home >
In the last article, I examined the process for updating AIR applications. If you haven't read that article, you might want to go back and brush up on the basics. In today's article, I will specifically covering how to update an application in ActionScript (for Flex or Flash).
One of the items that I covered in the last article was the update process. As a quick review, here are the five steps that I mentioned.
- 1. Determine the update version string for your application (the new version you will be updating to)
- 2. Download the correct version of that AIR application to local computer (preferably in the application resource directory)
- 3. Create an instance of the Updater class
- 4. Call the update method of the Updater class
- 5. AIR will shut down your AIR application, install the new version, and then restart the application
Scripting the Process
These steps are very general and apply to both ActionScript and JavaScript. Let's now look at the specific steps in ActionScript needed to update an application.
- 1. Determine the URL and version string of the application you will be updating to (there are many ways to accomplish this)
- 2. Create an instance of the URLStream class and pass it an instance of the URLRequest class (that points the URL from step 1). Since the URLStream.load method is asynchronous, you will need to add an event listener that will listen for then the URLStream is completed. (For our example today, I added an event listener that will update a progress bar as the file is downloaded - this is not required.)
- 3. After the download is complete, you will read the contents of the URLStream into a ByteArray.
- 4. You will now create a new File object in the application storage directory. You will also create a new FileStream object and read the ByteArray into the File object. Since this is an asynchronous process, you will also create an event listener for when this process completes.
- 5. Finally, you will create and instance of the Updater class and pass it the File object and the version you are updating to. AIR takes it from there.
The Example Application
While there are many steps to this process, I have provided code and a sample application that you can use to get started. This application allows you to switch between three versions of an application (that are identical except for their version string). This application also has 'View Source' enabled, so you can right click on the application and view the source code that I used to create it (or you can simply download the source code below).
Application Source Code
Download (4 kb)
Additional Resources
Fellow Rich Tretola has created an UpdateManager which can greatly ease the process for you. You can check out his blog for the details. I also wrote an article on the Adobe AIR Developer Center on using ColdFusion 8 to Manage Your AIR Updates. There also will be another resource released in the near future.






Facebook Application Development
I use Claus Wahlers' RemoteUpdater to do this .. the cool thing about that is that it uses Claus' FZip class to unzip the remote air file (without downloading the whole thing), reads the air file version from the application descriptor and then updates if needed .. as a result all you need on your server in the .air file
Makes things simple .. check it out http://codeazur.com.br/blog/air-remote-updater-upgraded-for-air-10/
I agree that the method you described is preferred in most situations. As I stated earlier there is something new that will be released soon.
I did want to be sure that everyone understood how the complete process works. This way can build their own update components to suit their specific needs.
The most important thing to remember is that it really doesn't matter which method of updating you choose as you could switch the method at any time. However, you will only have the option to change the update method if you have implemented some kind of update functionality. If you make the mistake of distributing an application without a built in method of update, it will become an orphaned application.
Rich is totally right on this one. Especially with smaller applications, it is tempting to put an application out without having the update functionality in the first version. It's key to get it in there the first time it is distributed to anyone outside of your development team.
Also, this is one of those situations where the process (updating your application) is perfect for abstraction and reuse. You will probably update all of your applications in the same manner. This way you can create your own class or use one of the community projects.
Yeah you are so right David.
I always use the Updater class that comes with AIR. What i did to suit my needs is develop a custom class that holds the Updater class for handling updates that can be called when ever needed and performed. It is the way to go. It doesn't take long ether. You then can be sure that the update will work every time because you know the ins and outs of your updater class.
Sending out an application with out a update feature is useless in my mind. What happens when you have a bug that every one is complaining about. You have to tell them to go back to you website to get them to download the fixed version. It is so much easier to just tell them to open up the program again and let it do the rest after you have put the latest version on your server.
It is great as well if you are developing a really small application to get it on their desktop (a seed) so it can grow into something bigger (A tree). Planting a seed allows to grow you application without really inconveniencing the end user.
I'm getting an error msg - "sorry , an error incurred while running...contact the author" both in my AIR app and in this sample App after updating the apps. Any suggestions?!
Tanks of Thanks,
Saran.
I just tested it - and everything seems to work OK on my end. What platform are you on? What browser are you using?
Hello David, thanks for the example.
I have split my AIR application into multiple RSL's to potentially reduce download time. However I am not sure how that will work with autoupdate!
Any ideas?
thanks in advance