-
[Flex] Custom AIR updater interface using ApplicationUpdater공부방/Flex 2012. 7. 20. 15:39
Update
I have updated the project to work with Flash Builder 4, you can get the code at this post.
Original Post:
To tell you the truth, I never gave the ApplicationUpdaterUI much thought in terms of memory use before this post. I just thought it was a great way to add a complete update system to your AIR applications. I had not thought it could be so memory intensive until a recent conversation with Jesse Warden on Twitter:

* Please note that Jesse is dude that looks about 17 and I am the older more distinguished gentleman.Problem with ApplicationUpdaterUI
Indeed, that “mofo eats mad RAM” is putting it lightly. It turns out that the ApplicationUpdaterUI consumes about 14MB of RAM within the application. Furthermore, for the ApplicationUpdaterUI to even check for available updates, it must loads the entire UI in memory even if not displayed. So just by using the framework, you end adding 14MB to your application that won’t be garbage collected. Granted, in most cases 14MB of RAM is not that big of deal. However, for smaller applications you might want to consider an alternative approach.
There happens to another class file called ApplicationUpdater. This class basically gives you all the benefits of the ApplicationUpdaterUI framework without any of the visible elements. This means you have to build your own user interface. This might actually be a benefit in the long run as you may want to customize your application updater to match your application. The other benefit is that you can use the ApplicationUpdater class to check for updates without loading any user interface. The interface only needs to be loaded if there is an actual update available.
Custom Updater Interface with ApplicationUpdater
In building my own custom updater interface, I thought it might be nice to have the same look and feel of the ApplicationUpdaterUI along with some of the more polite features (like postpone update until restart). Building your own updater using the ApplicationUpdater turns out to be a little more involved than I had originally thought. However, when you start attacking a problem you persevere until the end, no matter what the pain.
I did find some available information in the Adobe AIR 1.5 Cookbook, which has a basic custom updater example. This helped with some of the basic stuff, but I still needed a little more detail to make something similar to the ApplicationUpdaterUI. I found another good example by Jens Krause, but this example is for Flex 4. I needed something that would work for Flex 3. So here is what I built based on these examples:
The application consists of one class file and one MXML dialog for displaying all the user interface elements. I borrowed some of the icons from the ApplicationUpdaterUI which is available in the AIR SDK (I hope Adobe doesn’t mind). The update dialog UI is only loaded when needed, all checks for application updates happen using the ApplicationUpdater. The update dialog is only displayed when the user wants to manually update or the periodic update check finds a new application update.
The Good and the Bad
The good news is the updater only consumes about 2MB of RAM when you load the update dialog box, part of that is the ApplicationUpdater itself running in the background. The other good news is that you can yank out or customize any part of the this example to meet your own needs. The bad news is that even though I tried my best to fully remove the update dialog and have garbage collection clean it up, it doesn’t fully unload from memory (go figure). I don’t feel this is a huge issue as the application is most likely restarted after you install an update. Below is the code followed by a zip file containing the full application.
UpdateManager.as
001packagecom.thanksmister002{003importair.update.ApplicationUpdater;004importair.update.events.DownloadErrorEvent;005importair.update.events.StatusFileUpdateErrorEvent;006importair.update.events.StatusFileUpdateEvent;007importair.update.events.StatusUpdateErrorEvent;008importair.update.events.StatusUpdateEvent;009importair.update.events.UpdateEvent;010011importflash.desktop.NativeApplication;012importflash.events.ErrorEvent;013importflash.events.Event;014importflash.events.ProgressEvent;015importflash.filesystem.File;016017publicclassUpdateManager018{019privatevarappUpdater:ApplicationUpdater;020privatevarappVersion:String;021privatevarbaseURL:String;022privatevarupdaterDialog:UpdaterDialog;023privatevarconfigurationFile:File;024privatevarisFirstRun:String;025privatevarupateVersion:String;026privatevarapplicationName:String;027privatevarinstalledVersion:String;028privatevardescription:String;029030privatevarinitializeCheckNow:Boolean=false;031privatevarisInstallPostponed:Boolean=false;032privatevarshowCheckState:Boolean=true;033034/**035* Constructer for UpdateManager Class036*037* @param showCheckState Boolean value to show the Check Now dialog box038* @param initializeCheckNow Boolean value to initialize application and run check on instantiation of the Class039* */040publicfunctionUpdateManager(showCheckState:Boolean=true, initializeCheckNow:Boolean=false)041{042this.showCheckState = showCheckState;043this.configurationFile =newFile("app:/config/update.xml");044this.initializeCheckNow = initializeCheckNow;045initialize();046}047048publicfunctioncheckNow():void049{050//trace("checkNow");051isInstallPostponed =false;052if(showCheckState) {053createDialog(UpdaterDialog.CHECK_UPDATE);054}else{055appUpdater.checkNow();056}057}058059//---------- ApplicationUpdater ----------------//060061privatefunctioninitialize():void062{063//trace("initialize");064if(!appUpdater){065appUpdater =newApplicationUpdater();066appUpdater.configurationFile = configurationFile;067appUpdater.addEventListener(UpdateEvent.INITIALIZED, updaterInitialized);068appUpdater.addEventListener(StatusUpdateEvent.UPDATE_STATUS, statusUpdate);069appUpdater.addEventListener(UpdateEvent.BEFORE_INSTALL, beforeInstall);070appUpdater.addEventListener(StatusUpdateErrorEvent.UPDATE_ERROR, statusUpdateError);071appUpdater.addEventListener(UpdateEvent.DOWNLOAD_START, downloadStarted);072appUpdater.addEventListener(ProgressEvent.PROGRESS, downloadProgress);073appUpdater.addEventListener(UpdateEvent.DOWNLOAD_COMPLETE, downloadComplete);074appUpdater.addEventListener(DownloadErrorEvent.DOWNLOAD_ERROR, downloadError);075appUpdater.addEventListener(ErrorEvent.ERROR, updaterError);076appUpdater.initialize();077}078}079080privatefunctionbeforeInstall(event:UpdateEvent):void081{082//trace("beforeInstall");083if(isInstallPostponed) {084event.preventDefault();085isInstallPostponed =false;086}087}088089privatefunctionupdaterInitialized(event:UpdateEvent):void090{091//trace("updaterInitialized");092this.isFirstRun = event.target.isFirstRun;093this.applicationName = getApplicationName();094this.installedVersion = getApplicationVersion();095096if(showCheckState && initializeCheckNow) {097createDialog(UpdaterDialog.CHECK_UPDATE);098}elseif(initializeCheckNow) {099appUpdater.checkNow();100}101}102103privatefunctionstatusUpdate(event:StatusUpdateEvent):void104{105//trace("statusUpdate");106event.preventDefault();107if(event.available){108this.description = getUpdateDescription(event.details);109this.upateVersion = event.version;110111if(!showCheckState) {112createDialog(UpdaterDialog.UPDATE_AVAILABLE);113}elseif(updaterDialog) {114updaterDialog.applicationName =this.applicationName;115updaterDialog.installedVersion =this.installedVersion;116updaterDialog.upateVersion =this.upateVersion;117updaterDialog.description =this.description118updaterDialog.updateState = UpdaterDialog.UPDATE_AVAILABLE;119}120}else{121if(showCheckState) createDialog(UpdaterDialog.NO_UPDATE);122}123}124125privatefunctionstatusUpdateError(event:StatusUpdateErrorEvent):void126{127event.preventDefault();128if(!updaterDialog){129createDialog(UpdaterDialog.UPDATE_ERROR);130}else{131updaterDialog.updateState = UpdaterDialog.UPDATE_ERROR;132}133}134135privatefunctionstatusFileUpdate(event:StatusFileUpdateEvent):void136{137event.preventDefault();138if(event.available) {139updaterDialog.updateState = UpdaterDialog.UPDATE_DOWNLOADING;140appUpdater.downloadUpdate();141}else{142updaterDialog.updateState = UpdaterDialog.UPDATE_ERROR;143}144}145146privatefunctionstatusFileUpdateError(event:StatusFileUpdateErrorEvent):void147{148event.preventDefault();149updaterDialog.updateState = UpdaterDialog.UPDATE_ERROR;;150}151152privatefunctiondownloadStarted(event:UpdateEvent):void153{154updaterDialog.updateState = UpdaterDialog.UPDATE_DOWNLOADING;155}156157privatefunctiondownloadProgress(event:ProgressEvent):void158{159updaterDialog.updateState = UpdaterDialog.UPDATE_DOWNLOADING;160varnum:Number= (event.bytesLoaded/event.bytesTotal)*100;161updaterDialog.downloadProgress(num);162}163164privatefunctiondownloadComplete(event:UpdateEvent):void165{166event.preventDefault();// prevent default install167updaterDialog.updateState = UpdaterDialog.INSTALL_UPDATE;168}169170privatefunctiondownloadError(event:DownloadErrorEvent):void171{172event.preventDefault();173updaterDialog.updateState = UpdaterDialog.UPDATE_ERROR;174}175176privatefunctionupdaterError(event:ErrorEvent):void177{178updaterDialog.errorText = event.text;179updaterDialog.updateState = UpdaterDialog.UPDATE_ERROR;180}181182//---------- UpdaterDialog Events ----------------//183184privatefunctioncreateDialog(state:String):void185{186if(!updaterDialog) {187updaterDialog =newUpdaterDialog();188updaterDialog.isFirstRun =this.isFirstRun;189updaterDialog.applicationName =this.applicationName;190updaterDialog.installedVersion =this.installedVersion;191updaterDialog.upateVersion =this.upateVersion;192updaterDialog.updateState = state;193updaterDialog.description =this.description;194updaterDialog.addEventListener(UpdaterDialog.EVENT_CHECK_UPDATE, checkUpdate);195updaterDialog.addEventListener(UpdaterDialog.EVENT_INSTALL_UPDATE, installUpdate);196updaterDialog.addEventListener(UpdaterDialog.EVENT_CANCEL_UPDATE, cancelUpdate);197updaterDialog.addEventListener(UpdaterDialog.EVENT_DOWNLOAD_UPDATE, downloadUpdate);198updaterDialog.addEventListener(UpdaterDialog.EVENT_INSTALL_LATER, installLater);199updaterDialog.open();200}201}202203/**204* Check for update.205* */206privatefunctioncheckUpdate(event:Event):void207{208//trace("checkUpdate");209appUpdater.checkNow();210}211212/**213* Install the update.214* */215privatefunctioninstallUpdate(event:Event):void216{217appUpdater.installUpdate();218}219220/**221* Install the update.222* */223privatefunctioninstallLater(event:Event):void224{225isInstallPostponed =true;226appUpdater.installUpdate();227destoryUpdater();228}229230/**231* Download the update.232* */233privatefunctiondownloadUpdate(event:Event):void234{235appUpdater.downloadUpdate();236}237238/**239* Cancel the update.240* */241privatefunctioncancelUpdate(event:Event):void242{243appUpdater.cancelUpdate();244destoryUpdater();245}246247//---------- Destroy All ----------------//248249privatefunctiondestroy():void250{251if(appUpdater) {252appUpdater.configurationFile = configurationFile;253appUpdater.removeEventListener(UpdateEvent.INITIALIZED, updaterInitialized);254appUpdater.removeEventListener(StatusUpdateEvent.UPDATE_STATUS, statusUpdate);255appUpdater.removeEventListener(StatusUpdateErrorEvent.UPDATE_ERROR, statusUpdateError);256appUpdater.removeEventListener(UpdateEvent.DOWNLOAD_START, downloadStarted);257appUpdater.removeEventListener(ProgressEvent.PROGRESS, downloadProgress);258appUpdater.removeEventListener(UpdateEvent.DOWNLOAD_COMPLETE, downloadComplete);259appUpdater.removeEventListener(DownloadErrorEvent.DOWNLOAD_ERROR, downloadError);260appUpdater.removeEventListener(UpdateEvent.BEFORE_INSTALL, beforeInstall);261appUpdater.removeEventListener(ErrorEvent.ERROR, updaterError);262263264appUpdater =null;265}266267destoryUpdater();268}269270privatefunctiondestoryUpdater():void271{272if(updaterDialog) {273updaterDialog.destroy();274updaterDialog.removeEventListener(UpdaterDialog.EVENT_CHECK_UPDATE, checkUpdate);275updaterDialog.removeEventListener(UpdaterDialog.EVENT_INSTALL_UPDATE, installUpdate);276updaterDialog.removeEventListener(UpdaterDialog.EVENT_CANCEL_UPDATE, cancelUpdate);277updaterDialog.removeEventListener(UpdaterDialog.EVENT_DOWNLOAD_UPDATE, downloadUpdate);278updaterDialog.removeEventListener(UpdaterDialog.EVENT_INSTALL_LATER, installLater);279updaterDialog.close();280updaterDialog =null;281}282isInstallPostponed =false;283}284285//---------- Utilities ----------------//286287/**288* Getter method to get the version of the application289* Based on Jens Krause blog post: http://www.websector.de/blog/2009/09/09/custom-applicationupdaterui-for-using-air-updater-framework-in-flex-4/290*291* @return String Version of application292*293*/294privatefunctiongetApplicationVersion():String295{296varappXML:XML = NativeApplication.nativeApplication.applicationDescriptor;297varns:Namespace = appXML.namespace();298returnappXML.ns::version;299}300301/**302* Getter method to get the name of the application file303* Based on Jens Krause blog post: http://www.websector.de/blog/2009/09/09/custom-applicationupdaterui-for-using-air-updater-framework-in-flex-4/304*305* @return String name of application306*307*/308privatefunctiongetApplicationFileName():String309{310varappXML:XML = NativeApplication.nativeApplication.applicationDescriptor;311varns:Namespace = appXML.namespace();312returnappXML.ns::filename;313}314315/**316* Getter method to get the name of the application, this does not support multi-language.317* Based on a method from Adobes ApplicationUpdaterDialogs.mxml, which is part of Adobes AIR Updater Framework318* Also based on Jens Krause blog post: http://www.websector.de/blog/2009/09/09/custom-applicationupdaterui-for-using-air-updater-framework-in-flex-4/319*320* @return String name of application321*322*/323privatefunctiongetApplicationName():String324{325varapplicationName:String;326varxmlNS:Namespace=newNamespace("http://www.w3.org/XML/1998/namespace");327varappXML:XML=NativeApplication.nativeApplication.applicationDescriptor;328varns:Namespace=appXML.namespace();329330// filename is mandatory331varelem:XMLList=appXML.ns::filename;332333// use name is if it exists in the application descriptor334if((appXML.ns::name).length() !=0)335{336elem=appXML.ns::name;337}338339// See if element contains simple content340if(elem.hasSimpleContent())341{342applicationName=elem.toString();343}344345returnapplicationName;346}347348/**349* Helper method to get release notes, this does not support multi-language.350* Based on a method from Adobes ApplicationUpdaterDialogs.mxml, which is part of Adobes AIR Updater Framework351* Also based on Jens Krause blog post: http://www.websector.de/blog/2009/09/09/custom-applicationupdaterui-for-using-air-updater-framework-in-flex-4/352*353* @param detail Array of details354* @return String Release notes depending on locale chain355*356*/357protectedfunctiongetUpdateDescription(details:Array):String358{359vartext:String="";360361if(details.length ==1)362{363text=details[0][1];364}365returntext;366}367}368}UpdateDialog.mxml
001<?xml version="1.0"encoding="utf-8"?>002<mx:Window xmlns="*"xmlns:mx="http://www.adobe.com/2006/mxml"styleName="updateDialogWindow"003layout="absolute"maximizable="false"resizable="false"currentState="{_updateState}"004clipContent="false"showStatusBar="false"width="530"height="180">005006<mx:Metadata>007[Event(name="checkUpdate", type="flash.events.Event")]008[Event(name="downloadUpdate", type="flash.events.Event")]009[Event(name="downloadUpdate", type="flash.events.Event")]010[Event(name="cancelUpdate", type="flash.events.Event")]011</mx:Metadata>012013<mx:Script>014<![CDATA[015publicstaticvarEVENT_CHECK_UPDATE:String="checkUpdate";016publicstaticvarEVENT_INSTALL_UPDATE:String="installUpdate";017publicstaticvarEVENT_DOWNLOAD_UPDATE:String="downloadUpdate";018publicstaticvarEVENT_CANCEL_UPDATE:String="cancelUpdate";019publicstaticvarEVENT_INSTALL_LATER:String="installLater";020021[Bindable]publicstaticvarUPDATE_DOWNLOADING:String="updateDownloading";022[Bindable]publicstaticvarINSTALL_UPDATE:String="installUpdate";023[Bindable]publicstaticvarUPDATE_AVAILABLE:String="updateAvailable";024[Bindable]publicstaticvarNO_UPDATE:String="noUpdate";025[Bindable]publicstaticvarCHECK_UPDATE:String="checkUpdate";026[Bindable]publicstaticvarUPDATE_ERROR:String="updateError";027028[Bindable]privatevar_isFirstRun:String;029[Bindable]privatevar_installedVersion:String;030[Bindable]privatevar_updateVersion:String;031[Bindable]privatevar_updateDescription:String;032[Bindable]privatevar_applicationName:String;033[Bindable]privatevar_updateState:String;034[Bindable]privatevar_errorText:String="There was an error checking for updates.";035036publicfunctionsetisFirstRun(value:String):void037{038_isFirstRun = value;039}040041publicfunctionsetinstalledVersion(value:String):void042{043_installedVersion = value;044}045046publicfunctionsetupateVersion(value:String):void047{048_updateVersion = value;049}050051publicfunctionsetupdateState(value:String):void052{053_updateState = value;054}055056publicfunctionsetapplicationName(value:String):void057{058_applicationName = value;059}060061publicfunctionsetdescription(value:String):void062{063_updateDescription = value;064}065066publicfunctionseterrorText(value:String):void067{068_errorText = value;069}070071publicfunctiondownloadProgress(value:Number):void072{073if(progressBar) progressBar.setProgress(value,100);074}075076privatefunctioncontinueUpdate():void077{078if(this.currentState == UpdaterDialog.CHECK_UPDATE){079this.dispatchEvent(newEvent(EVENT_CHECK_UPDATE));080}elseif(this.currentState == UPDATE_AVAILABLE) {081this.dispatchEvent(newEvent(EVENT_DOWNLOAD_UPDATE));082}elseif(this.currentState == INSTALL_UPDATE) {083this.dispatchEvent(newEvent(EVENT_INSTALL_UPDATE));084}085}086087privatefunctioncancelUpdate():void088{089if(this.currentState == INSTALL_UPDATE) {090this.dispatchEvent(newEvent(EVENT_INSTALL_LATER));091return;092}093this.dispatchEvent(newEvent(EVENT_CANCEL_UPDATE));094}095096publicfunctiondestroy():void097{098iconImage.unloadAndStop(true);099iconImage.source =null;100101continueButton.removeEventListener(MouseEvent.CLICK, continueUpdate);102cancelButton.removeEventListener(MouseEvent.CLICK, cancelUpdate);103104// becaause we used skins, we have to clear them for garbage collection106continueButton.styleName =null;107cancelButton.styleName =null;108109while(this.numChildren >0){110this.removeChildAt(0);111}112}113]]>114</mx:Script>115116<mx:states>117<mx:State name="{CHECK_UPDATE}">118<mx:AddChild position="lastChild">119<mx:Label x="152"y="86"text="Application:"styleName="updateDialogLabel"/>120</mx:AddChild>121<mx:AddChild position="lastChild">122<mx:Text x="230"y="86"text="{this._applicationName}"styleName="updateDialogText"/>123</mx:AddChild>124<mx:AddChild position="lastChild">125<mx:Label x="107"y="19"text="Check for updates"styleName="updateTitle"/>126</mx:AddChild>127<mx:AddChild position="lastChild">128<mx:Text x="107"y="50"text="Allow the application to check for updates?"styleName="updateDialogText"/>129</mx:AddChild>130<mx:SetProperty name="height"value="180"/>131</mx:State>132<mx:State name="{UPDATE_AVAILABLE}">133<mx:SetProperty name="height"value="360"/>134<mx:AddChild position="lastChild">135<mx:Text text="{this._installedVersion}"x="230"y="114"styleName="updateDialogText"/>136</mx:AddChild>137<mx:AddChild position="lastChild">138<mx:Text text="{this._updateVersion}"x="230"y="134"styleName="updateDialogText"/>139</mx:AddChild>140<mx:AddChild position="lastChild">141<mx:Label x="118"y="114"text="Installed Version:"styleName="updateDialogLabel"/>142</mx:AddChild>143<mx:AddChild position="lastChild">144<mx:Label x="127"y="134"text="Update Version:"styleName="updateDialogLabel"/>145</mx:AddChild>146<mx:AddChild position="lastChild">147<mx:Label x="152"y="96"text="Application:"styleName="updateDialogLabel"/>148</mx:AddChild>149<mx:AddChild position="lastChild">150<mx:Text x="230"y="96"text="{this._applicationName}"styleName="updateDialogText"/>151</mx:AddChild>152<mx:AddChild position="lastChild">153<mx:Label x="107"y="19"text="Update Available"styleName="updateTitle"/>154</mx:AddChild>155<mx:AddChild position="lastChild">156<mx:Text x="107"y="50"text="An updated version of the application is available for download."styleName="updateDialogText"/>157</mx:AddChild>158159<mx:AddChild position="lastChild">160<mx:Label id="releaseLabel"x="10"y="222"text="Release notes"styleName="updateDialogLabel"/>161</mx:AddChild>162<mx:AddChild position="lastChild">163<mx:TextArea text="{_updateDescription}"x="10"y="248"width="508"height="100"styleName="updateDialogTextArea"/>164</mx:AddChild>165166<mx:AddChild position="lastChild">167<mx:HRule x="10"y="214"width="508"styleName="updateDialogHRule"/>168</mx:AddChild>169<mx:SetProperty target="{cancelButton}"name="y"value="164"/>170<mx:SetProperty target="{continueButton}"name="y"value="164"/>171<mx:SetProperty target="{cancelButton}"name="label"value="Download later"/>172<mx:SetProperty target="{continueButton}"name="x"value="269"/>173<mx:SetProperty target="{continueButton}"name="label"value="Download now"/>174</mx:State>175<mx:State name="{NO_UPDATE}">176<mx:AddChild position="lastChild">177<mx:Label x="122"y="86"text="Application:"styleName="updateDialogLabel"/>178</mx:AddChild>179<mx:AddChild position="lastChild">180<mx:Text x="200"y="86"text="{this._applicationName}"styleName="updateDialogText"/>181</mx:AddChild>182<mx:AddChild position="lastChild">183<mx:Label x="107"y="19"text="No Updates"styleName="updateTitle"/>184</mx:AddChild>185<mx:AddChild position="lastChild">186<mx:Text x="107"y="50"text="There is no application update available at this time."styleName="updateDialogText"/>187</mx:AddChild>188<mx:RemoveChild target="{continueButton}"/>189<mx:SetProperty target="{cancelButton}"name="label"value="Close"/>190<mx:SetProperty name="height"value="180"/>191</mx:State>192<mx:State name="{UPDATE_DOWNLOADING}">193<mx:AddChild position="lastChild">194<mx:ProgressBar x="107"y="84"width="411"label=" "id="progressBar"mode="manual"height="15"styleName="updateDiallogProgress"/>195</mx:AddChild>196<mx:AddChild position="lastChild">197<mx:Text x="107"y="20"text="Downloading Update"styleName="updateTitle"/>198</mx:AddChild>199<mx:RemoveChild target="{continueButton}"/>200<mx:AddChild position="lastChild">201<mx:Label x="107"y="53"text="Download progress..."styleName="updateDialogLabel"/>202</mx:AddChild>203<mx:SetProperty name="height"value="180"/>204</mx:State>205<mx:State name="{UPDATE_ERROR}">206<mx:AddChild position="lastChild">207<mx:Label x="107"y="19"text="Unexpected error"styleName="updateTitle"/>208</mx:AddChild>209<mx:AddChild position="lastChild">210<mx:Label x="107"y="50"text="{_errorText}"styleName="updateDialogLabel"/>211</mx:AddChild>212<mx:RemoveChild target="{continueButton}"/>213<mx:SetProperty target="{cancelButton}"name="label"value="Close"/>214<mx:SetProperty name="height"value="180"/>215</mx:State>216<mx:State name="{INSTALL_UPDATE}">217<mx:AddChild position="lastChild">218<mx:Text text="{this._installedVersion}"x="230"y="139"styleName="updateDialogText"/>219</mx:AddChild>220<mx:AddChild position="lastChild">221<mx:Text text="{this._updateVersion}"x="230"y="159"styleName="updateDialogText"/>222</mx:AddChild>223<mx:AddChild position="lastChild">224<mx:Label x="118"y="139"text="Installed Version:"styleName="updateDialogLabel"/>225</mx:AddChild>226<mx:AddChild position="lastChild">227<mx:Label x="127"y="159"text="Update Version:"styleName="updateDialogLabel"/>228</mx:AddChild>229<mx:AddChild position="lastChild">230<mx:Label x="152"y="121"text="Application:"styleName="updateDialogLabel"/>231</mx:AddChild>232<mx:AddChild position="lastChild">233<mx:Text x="230"y="121"text="{this._applicationName}"styleName="updateDialogText"/>234</mx:AddChild>235<mx:AddChild position="lastChild">236<mx:Label x="107"y="19"text="Install update"id="windowTitle4"styleName="updateTitle"/>237</mx:AddChild>238<mx:AddChild position="lastChild">239<mx:Text x="107"y="50"text="The update for the application is downloaded and ready to be installed."styleName="updateDialogText"/>240</mx:AddChild>241242<mx:AddChild position="lastChild">243<mx:Label x="10"y="262"text="Release notes"styleName="updateDialogLabel"/>244</mx:AddChild>245<mx:AddChild position="lastChild">246<mx:TextArea id="relaeseNotesTextArea0"text="{_updateDescription}"x="10"y="288"width="508"height="100"styleName="updateDialogTextArea"/>247</mx:AddChild>248<mx:SetProperty name="height"value="402"/>249<mx:AddChild position="lastChild">250<mx:ProgressBar id="installProgressBar"x="107"y="84"width="411"label=" "mode="manual"height="15"styleName="installDiallogProgress"creationComplete="installProgressBar.setProgress(100,100)"/>251</mx:AddChild>252<mx:AddChild position="lastChild">253<mx:HRule x="10"y="249"width="508"styleName="updateDialogHRule"/>254</mx:AddChild>255<mx:SetProperty target="{cancelButton}"name="label"value="Postpone until restart"/>256<mx:SetProperty target="{cancelButton}"name="y"value="198"/>257<mx:SetProperty target="{continueButton}"name="y"value="198"/>258<mx:SetProperty target="{continueButton}"name="x"value="320"/>259<mx:SetProperty target="{continueButton}"name="label"value="Install update"/>260</mx:State>261</mx:states>262263<mx:Button x="107"y="129"label="Cancel"id="cancelButton"click="cancelUpdate()"height="34"styleName="updateDialogButton"/>264<mx:Button x="202"y="129"label="Check for Updates"id="continueButton"click="continueUpdate()"height="34"styleName="updateDialogButton"/>265<mx:Image source="@Embed('/assets/images/UpdateIcon.png')"x="15"y="25"width="81"height="74"id="iconImage"/>266267</mx:Window>Main.mxml
01<?xml version="1.0"encoding="utf-8"?>02<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"03layout="vertical"width="428"height="280"creationComplete="init()">0405<mx:Style source="assets/styles.css"/>0607<mx:Script>08<![CDATA[09importcom.thanksmister.UpdateManager;10importmx.rpc.events.ResultEvent;1112privatevarupdater:UpdateManager;13[Bindable]privatevarbaseURL:String;14[Bindable]privatevarupdates:String;1516privatefunctioninit():void17{18configService.send();19}2021privatefunctionhandleResult(event:ResultEvent):void22{23varxml:XML = event.resultasXML;24baseURL = xml..baseurl.toString();25updates = xml..updates.toString();2627if(updates)28updater =newUpdateManager(true,false);29}30]]>31</mx:Script>3233<mx:HTTPService id="configService"method="GET"resultFormat="e4x"url="config/configuration.xml"result="handleResult(event)"/>3435<mx:Text fontSize="14"color="0xFFFFFFF"text="Update tester. Please click the button below to begin update checking or wait for the dealy time (3 min). Once the application is successfully updated, the application version will be updated from v1 to v2."x="10"y="10"width="342"height="104"/>3637<mx:Buttonlabel="Begin update process"color="0xFFFFFFF"x="125"y="104"click="updater.checkNow()"/>3839<mx:Label id="versionText"fontSize="14"color="0xFFFFFFF"/>40<mx:Label text="{'Base URL: ' + baseURL}"color="0xFFFFFFF"/>41<mx:Label text="{'Updates: ' + updates}"color="0xFFFFFFF"/>42</mx:WindowedApplication>I packed up the Flex project. You would use this basically the same as you would use the ApplicationUpdaterUI framework. You need to create an update version of your AIR file and place it and update.xm file on a server. You can test it from the local IDE if you replace the server url with “app:/”. Just remember you can not actually update an AIR application from the IDE, it has to be installed and running on your machine to update, and the update files have to be accessible just like when you use the ApplicationUpdaterUI.
The code is free to use, hose, rip apart, just post back any fixes or enhancements you make.
Source Files
Update
Don’t forget to add a closing event handler to the dialog box that calls the destory() function. This was not in the original code and there needs to be a way to handle users clicking on the close box of the Window for the update dialog user interface. I also added a change that if you don’t want to show the check for update now option, the “no update available” dialog does not appear either, here is the updated code for statusUpdate function in UpdateManager.as (not in the downloaded zip):
01privatefunctionstatusUpdate(event:StatusUpdateEvent):void02{03//trace("statusUpdate");04event.preventDefault();05if(event.available){06this.description = getUpdateDescription(event.details);07this.upateVersion = event.version;0809if(!showCheckState) {10createDialog(UpdaterDialog.UPDATE_AVAILABLE);11}elseif(updaterDialog) {12updaterDialog.applicationName =this.applicationName;13updaterDialog.installedVersion =this.installedVersion;14updaterDialog.upateVersion =this.upateVersion;15updaterDialog.description =this.description16updaterDialog.updateState = UpdaterDialog.UPDATE_AVAILABLE;17}18}else{19if(showCheckState) createDialog(UpdaterDialog.NO_UPDATE);20}21}-Mister
'공부방 > Flex' 카테고리의 다른 글
FlexBuilder(FlashBuilder)에서 Profiler(프로파일링) 사용 (0) 2016.10.06 [Flex] ApplicationUpdater 클래스로 Adobe AIR 자동 업데이트 (0) 2012.07.20 [Flex] 대용량 파일 전송 (0) 2012.07.18 Communicating between Flash Player and Adobe AIR with sockets (0) 2012.07.13 [Flex] Combobox 텍스트 입력 자동 완성 (0) 2012.04.09


