Create and deliver your own elearning using eduslide.net

Browse thousands of lessons. Create your own and share the knowledge.

Sign up for a free eduslide account !
Create your own courses.
Access thousands of lessons.

adobe air - building applications with adobe air

building applications with adobe air

Author: dhanesh

automatic installation using Flex 3

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

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
 xmlns:compo="compo.*" layout="absolute" width="1024" height="768" styleName="parentApp" showStatusBar="false" creationComplete="{checkVersion();}">
 
     // ActionScript file
  import compo.*;
  import mx.states.RemoveChild;
  import mx.states.AddChild;
  import mx.controls.*;
  import mx.collections.*;
  import mx.events.*;
  import mx.rpc.*;
  import mx.rpc.events.ResultEvent;
  import mx.rpc.events.FaultEvent;
  
  import flash.filesystem.FileStream;
  import flash.filesystem.File;
  import flash.filesystem.FileMode;
  import flash.desktop.Updater;
  import mx.events.CloseEvent;
   
   private var urlString:String;
   private var urlReq:URLRequest;
   private var urlStream:URLStream = new URLStream();
   private var fileData:ByteArray = new ByteArray();
   
  
//  import mx.core.UIComponent;
//  import mx.core.IUIComponent;
//  import flash.events.Event;

  import scripts.global;
  public var mainTabs1:tabNav;
  
  private var latestVersion:Number;
  private var latestFileName:String;
  private var latestDetails:String;
  private var fromPref:Boolean = false;
  private var thisVersionNo:Number=1.09;


  public function invokeServer():void{
   var inputVars:Array = new Array();
   inputVars["userName"] = loginId.userName.text;
   inputVars["password"] = loginId.password.text;
   loginId.rmObject.concurrency;
   loginId.rmObject.phpAuthenticate(inputVars);
  }
  
  public function doValidationResult(result:ResultEvent):void{
   if(result.result.loginStatus=='1'){
    mainTabs1 = new tabNav();
    global.userId = result.result.userId;
    global.userName = result.result.userName;
    global.role  = result.result.role;
    global.email  = result.result.email;
    mainAppBox.removeAllChildren();
    mainAppBox.addChild(mainTabs1);
   }else{
    Alert.show('Invalid user name or password');
   }
  }
  
  public function goToError(fault:FaultEvent):void{ 
   Alert.show("Server - " + fault.fault.faultString, "Error" );
  }
  
  private function checkVersion():void{
   versionTest.send();
  }  
  // Check Results of HTTPService
  private function testVersion(event:ResultEvent):void{
   latestVersion = event.result.latestVersion;
   latestFileName = event.result.latestFileName;
   latestDetails = event.result.latestDetails;
    if(thisVersionNo < latestVersion){
    Alert.show("There is an update available, would you like to get it now?\n\nDetails:\n"+latestDetails, "New Update", 3, this, alertClickHandler);
    } else {
     mainAppBox.visible=true;
     mainAppBox.includeInLayout = true;
     if(fromPref){
      Alert.show("There are no new updates available", "Information");
     }
    }
  }

  private function alertClickHandler(event:CloseEvent):void {
         if (event.detail==Alert.YES){
             getUpdate();
             showProgress.visible = true;
             trace("getUpdate");
            } else{
             mainAppBox.visible=true;
     mainAppBox.includeInLayout = true;
            }
        }
       
     // Download the updated .air file
  private function getUpdate():void{
   urlString = "http://weburl.com/versions/;
    urlReq = new URLRequest(urlString);
    urlStream.addEventListener(Event.COMPLETE, loaded);
    urlStream.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    urlStream.load(urlReq);
  }
  
  // Handle urlStream ProgressEvent
  private function progressHandler(event:ProgressEvent):void {
    trace("Download Progress "+(event.bytesLoaded*100)/event.bytesTotal+"%");
    downloadProgress.setProgress(event.bytesLoaded, event.bytesTotal)
  }
  
  // Handle urlStream COMPLETE Event and call writeAirFile()
  private function loaded(event:Event):void {
   urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);
   trace("urlStream");
      writeAirFile();
  }
  
  // Write air file to disk and store in appStorageDirectory
  private function writeAirFile():void {
   var file:File = File.applicationStorageDirectory.resolvePath(latestFileName);
   var fileStream:FileStream = new FileStream();
      fileStream.addEventListener(Event.CLOSE, fileClosed);
      fileStream.openAsync(file, FileMode.WRITE);
      fileStream.writeBytes(fileData, 0, fileData.length);
   fileStream.close();
  }
  
  // Handle CLOSE Event when file write has completed and call update to update application install
  private function fileClosed(event:Event):void {
   trace("fileClosed");
   Alert.show("Update is Downloaded and ready to Install.You can Install now .\n\nNote:\nInstallation will automatically restart the application.", "Install Update", 3, this, alertInstallHandler);  
   showProgress.visible = false;
  }
  
  private function alertInstallHandler(event:CloseEvent):void {
      if (event.detail==Alert.YES){
          var updater:Updater = new Updater();
          var airFile:File = File.applicationStorageDirectory.resolvePath(latestFileName);
     var version:String = String(latestVersion);
    updater.update(airFile, version);
         }else{
          this.parentApplication.updateFileAvailable = true;
         }
  }
  private function stopDown():void {
  // Alert.show("This will stop downloading update. You won't be able to resume.\nYou can later update the application from 'Preferences'.", "Stop Update", 3, this, alertStopDownHandler);    
  }

   ]]>
 
  
 
 
  
  
 
 http://weburl.com/versions/version.xml" useProxy="false" method="GET" resultFormat="object" result="testVersion(event)"/>

</mx:WindowedApplication>

 

 Here is the version.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<latestVersion>1.09</latestVersion>
<latestFileName>authorManLive.air</latestFileName>
<latestDetails>Updates from the admin. Password field changed for testing.</latestDetails>

 

Course options

Search

Activity

dhanesh modified the course adobe air - building applications with adobe air
dhanesh modified the course adobe air - building applications with adobe air
dhanesh modified the course adobe air - building applications with adobe air
dhanesh modified the lesson application installer
dhanesh modified the lesson application installer
dhanesh modified the lesson application installer
dhanesh created the lesson application installer
dhanesh modified the course adobe air - building applications with adobe air
dhanesh modified the course adobe air-building applications with adobe air
dhanesh created the course adobe air - building applications with adobe air