1 Reply Latest reply on Apr 6, 2010 6:21 AM by Catalin Anastasoaie

    Auto update using AIR 2.0

    Jayagopal Flex Level 1

      This is my code

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:WindowedApplication

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontWeight="bold"

      textDecoration="

      underline" creationComplete="preCheckForUpdate()">

       

      <mx:Script>

       

      <![CDATA[

       

      import air.update.ApplicationUpdater;

       

       

      import flash.events.ErrorEvent;

       

       

      import flash.events.IOErrorEvent;

       

       

      import air.update.ApplicationUpdaterUI;

       

       

      import air.update.events.UpdateEvent;

       

       

      import mx.controls.Alert;

       

       

       

      private var appUpdater:ApplicationUpdater = new ApplicationUpdater();

       

       

      private var updateXMLURL:String = "http://localhost/AutoUpdate1/update.xml";

       

       

      // Pre-read the server-side XML file to look for <force>yes</force>

       

       

      private function preCheckForUpdate():void

      {

       

      try

      {

       

       

      var loader:URLLoader = new URLLoader();

       

      loader.addEventListener(Event.COMPLETE, checkForUpdate);

       

      loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

      // Just in case we can't read the update.xml

      loader.load(

      new URLRequest(updateXMLURL));

      }

       

      catch(e:Error)

      {

      Alert.show(e.toString());

      }

       

      }

       

       

      private function checkForUpdate(event:Event):void

      {

       

       

      try

      {

      setApplicationVersion();

      // Find the current version so we can show it below

       

       

       

       

      var myXML:XML = new XML(event.target.data);

       

       

      namespace items = "http://ns.adobe.com/air/framework/update/description/2.0beta2";

       

       

      use namespace items;

       

       

      var forceUpdate:String = myXML.force;

       

       

       

      appUpdater.updateURL = updateXMLURL;

      // Server-side XML file describing update

       

       

      //appUpdater.isCheckForUpdateVisible = false; // We won't ask permission to check for an update

       

       

       

       

      // If <force>yes</force> was found above, turn off the download and install dialogs

       

       

      /* if(forceUpdate.toLowerCase() == "yes") {

       

      appUpdater.isDownloadUpdateVisible = false;

       

      appUpdater.isInstallUpdateVisible = false;

       

      } */

       

      appUpdater.addEventListener(UpdateEvent.INITIALIZED, onUpdate);

      // Once initialized, run onUpdate

       

       

      //appUpdater.addEventListener(ErrorEvent.ERROR, onError); // If something goes wrong, run onError

       

      appUpdater.initialize();

      // Initialize the update framework

      }

       

      catch(e:Error)

      {

      Alert.show(e.toString());

      }

       

      }

       

       

      private function onError(event:ErrorEvent):void {

       

      Alert.show(event.toString());

       

      }

       

      private function onIOError(event:IOErrorEvent):void

       

      {

      Alert.show(event.toString());

       

      trace("Error loading URL.");

      }

       

       

      private function onUpdate(event:UpdateEvent):void

      {

       

      try

      {

      appUpdater.checkNow();

      // Go check for an update now

      }

       

      catch(e:Error)

      {

      Alert.show(e.toString());

      }

       

      }

       

       

       

       

      // Find the current version for our Label below

       

       

      private function setApplicationVersion():void

      {

       

      try

      {

       

       

      var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;

       

       

      var ns:Namespace = appXML.namespace();

      ver.text =

      "Current version is " + appXML.ns::version;

      }

       

      catch(e:Error)

      {

      Alert.show(e.toString());

      }

       

      }

       

      ]]>

       

       

      </mx:Script>

       

      <mx:WipeRight

       

      id="slowright" duration="1000"/>

       

      <mx:Label x="93" y="135" text="Welcome to Rapidcare" fontSize="36" fontFamily="Times New Roman" color="#3C0B1F"

      creationCompleteEffect="

      {slowright}" height="89"/>

       

      <mx:Label x="178" y="186" color="#F81908" fontSize="36" fontWeight="bold" textDecoration="normal" id="ver"/>

       

      <mx:Label x="93" y="279" text="Hai"/>

       

      </mx:WindowedApplication>

       

      IT throws an error in this appUpdater.checkNow();

       

      Error #2044: Unhandled updateError:. text=unknown update version

       

       

      Please any provide solution for this

       

      Regards,

      Jayagopal