• Home
  • About Me
  • AIR Central
  • AS3 Libs
  • Books
  • Flex Central
  • Resources
  • The Guru's
  •  

    AIR ConnectionManager + UpdateManager

    The AIR ConnectionManager and UpdateManager classes work perfectly well individually however, I recommend that they are used together to ensure that your application will stay up to date by checking for updates when an Internet connection is present.

    There are 2 examples below.

    The first creates an instance of the ConnectionManager and an instance of the UpdateManager with the UpdateManager’s second constructor argument set to false. This will prevent the UpdateManager from automatically checking for an update on creation. Next a Button component is added with the enabled property bound to the ConnectionManager’s isConnected property. This will ensure that the user can only check for an available update when an Internet connection exists.

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    3.     layout="absolute">
    4.    
    5.     <mx:Script>
    6.         <![CDATA[
    7.             import com.everythingflex.air.managers.UpdateManager;
    8.             import com.everythingflex.air.managers.ConnectionManager;
    9.             [Bindable]
    10.             private var cm:ConnectionManager = new ConnectionManager();
    11.            
    12.             private var um:UpdateManager = new UpdateManager("http://www.yourdomain.com/appName/version.xml",false);
    13.            
    14.         ]]>
    15.     </mx:Script>
    16.    
    17.    
    18.     <mx:Label text="Hello World!" fontSize="20"
    19.         horizontalCenter="0" y="120"/>
    20.    
    21.     <mx:Button label="Check for Update"
    22.         click="um.checkForUpdate()"
    23.         enabled="{cm.isConnected}"
    24.         horizontalCenter="0" y="160"/>
    25.    
    26. </mx:WindowedApplication>

    The second example sets up an event listener within the init() function which will fire whenever the connection status changes. The event handler (the connectionChange() function) will call the UpdateManagers checkForUpdate() function if the isConected property is true.

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    3.     layout="absolute" creationComplete="init()">
    4.    
    5.     <mx:Script>
    6.         <![CDATA[
    7.             import com.everythingflex.air.managers.UpdateManager;
    8.             import com.everythingflex.air.managers.ConnectionManager;
    9.             [Bindable]
    10.             private var cm:ConnectionManager = new ConnectionManager();
    11.            
    12.             private var um:UpdateManager = new UpdateManager("http://www.everythingflex.com/AIR/UMTest/version.xml",false);
    13.            
    14.             private function init():void{
    15.                 cm.addEventListener(StatusEvent.STATUS,connectionChange);
    16.             }
    17.            
    18.             private function connectionChange(event:StatusEvent):void{
    19.                 if(event.target.isConnected)um.checkForUpdate();
    20.             }
    21.            
    22.         ]]>
    23.     </mx:Script>
    24.    
    25.    
    26.     <mx:Label text="Hello World!" fontSize="20"
    27.         horizontalCenter="0" y="120"/>
    28.    
    29.     <mx:Button label="Check for Update"
    30.         click="um.checkForUpdate()"
    31.         enabled="{cm.isConnected}"
    32.         horizontalCenter="0" y="160"/>
    33.    
    34. </mx:WindowedApplication>

    14 Responses to “AIR ConnectionManager + UpdateManager”

    1. tj Says:

      I have to say I love these classes, and thanks! I do have a question though- is the source for the UpdateManager available, or do you have any plans to make it available? For example, I would like to do things like tweak the Alert message.
      Thanks again!

    2. tj Says:

      Or inform the user that an update is about to be installed (in the case of a forced update)!

    3. everythingflex Says:

      Yes, I will be moving the source to google code shortly. The source is also in my AIR book at:
      http://blog.everythingflex.com/2008/03/19/get-a-free-flex-book/

    4. Andrea Says:

      What about the users permissions? Can a not-administrator user download the xml file for the check? and update the application?

      Thanks

    5. everythingflex Says:

      The XML file is read and parsed by the ConnectionManager. It should not be a problem for a non admin as it simply requires Internet access. The download of the new AIR install file and install could certainly have permission issues as it does require install privileges.

    6. Sergi Says:

      I have a problem: don’t run correcty.
      my problem is:
      my app descriptor’s version field is that:

      –AIR-app.xml–


      v1

      and I have a version.xml file like that:

      —-

      when I execute this code:

      var um : UpdateManager = new UpdateManager(”http://www.mywebsitecom/AIR_appDescriptors/version.xml”, false);

      um.checkForUpdate();

      returns true, when the version field are de same, and this means that there isn’t any update. What I do wrong?

      Exuse my wrong english please, I write from spain… ;)

    7. Sergi Says:

      excuse me:

      AIR-app.xml version field is : v1

      and version.xml is :

      when version is v1

    8. Sergi Says:

      link on version.xml is: http://sgeno.com/AIR_appDescriptors/version.xml

    9. everythingflex Says:

      So, you would need to pass http://sgeno.com/AIR_appDescriptors/version.xml into the UpdateManager constructor:

      var um : UpdateManager = new UpdateManager(”http://sgeno.com/AIR_appDescriptors/version.xml”, false);

      Also, it appears that the path to your downloadLocation defined within http://sgeno.com/AIR_appDescriptors/version.xml is incorrect as it is currently pointing to a fake location.

    10. Sergi Says:

      yes, I have like you say:

      var um : UpdateManager = new UpdateManager(”http://sgeno.com/AIR_appDescriptors/version.xml”, false);
      um.checkForUpdate();

      this is the correct code I have in my program

    11. Sergi Says:

      why you say that my downloadLocation defined within http://sgeno.com/AIR_appDescriptors/version.xml is incorrect ? I can go and see xml file!?

    12. everythingflex Says:

      You currently have the downloadLocation property of the version.xml file set to:
      http://www.yourdomain.com/AIR/UMTest/UM.air

      Unless you actually own the domain name yourdomain.com, I suspect this is not the correct path to teh downloadLocation of your air file.

    13. Sergi Says:

      can I change the text of update information alert ?

    14. everythingflex Says:

      You can change the text that appears by adjusting the message property of your version.xml file.

    Leave a Reply