A.10. Make It Self-Updating

Another issue that was a non-issue when this was a Flex Web-based application is version control. Back then, if we wanted to push out a new version, we would simply upload the changes to the server, and on the next visit the user would get the new version. With an AIR application, our users are not visiting our server on each run of the application, so we could easily lose control over our application. The solution to this is to program a self-updating scheme. It is very important that you implement this on the first version you release or you will wind up with applications that are orphans with no chance of being updated unless the user actively requests the update. Note that this solution is one that I created and is not an official Adobe method for doing application updates.

Please follow these steps to add self-updating to the WeatherAIR application.

Create a new ActionScript class named UpdateManager within the com.everthingflex.air.managers package, and enter the contents of Listing A-5 into this new class.

Example A-5. The UpdateManager class
package com.everythingflex.air.managers
{
    import flash.desktop.NativeApplication;
    import flash.desktop.Updater;
import  flash.events.Event;
    import  flash.filesystem.File;
    import  flash.filesystem.FileMode;
    import  flash.filesystem.FileStream;
    import  flash.net.URLRequest;
    import  flash.net.URLStream;
    import  flash.utils.ByteArray;

    import  mx.controls.Alert;
    import  mx.events.CloseEvent;
    import  mx.rpc.events.FaultEvent; ...

Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.