The principle of automatic air update is actually very simple. applicationupdaterui will read a version description file on the network. The description file is a specific XML document, it contains the version number, the corresponding installation file path, and the update description. Then compare it with the current air program version to determine whether to download and install it.
How can I Configure Automatic Air upgrade successfully? There are roughly two steps:
1. ActionScript:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <s: Drawing wedapplication xmlns: FX = "http://ns.adobe.com/mxml/2009" <br/> xmlns: S = "Library: // ns.adobe.com/flex/spark" <br/> xmlns: MX = "Library: // ns.adobe.com/flex/mx" <br/> creationcomplete = "versioncheck ();"> </P> <p> <FX: SCRIPT> <br/> <! -- [CDATA [<br/> import air. update. applicationupdaterui; <br/> import air. update. events. updateevent; </P> <p> private function versioncheck (): void <br/> {<br/> // display the current version <br/> var appxml: xml = nativeapplication. nativeapplication. applicationdescriptor; <br/> var ns: namespace = appxml. namespace (); </P> <p> TXT. text + = appxml. NS: version; </P> <p> // update <br/> var appupdate: applicationupdaterui = new applicationupd Aterui (); </P> <p> appupdate. updateurl = "http: // localhost/air_update/update. XML "; <br/> appupdate. ischeckforupdatevisible = false; <br/> appupdate. isfileupdatevisible = false; <br/> appupdate. isinstallupdatevisible = false; </P> <p> appupdate. addeventlistener (updateevent. initialized, onupdatehandler); <br/> appupdate. addeventlistener (errorevent. error, onerrorhandler); </P> <p> appupdate. initialize (); </P> <p> tr ACE (appupdate. currentVersion ); <br/>}</P> <p>/** <br/> * onupdatehandler <br/> * automatic update initialization <br/> *@ param updateevent EVT <br/> * @ return void <br/> ***/<br/> private function onupdatehandler (EVT: updateevent): void <br/>{< br/> var target: applicationupdaterui = EVT. currenttarget as applicationupdaterui; </P> <p> target. removeeventlistener (updateevent. initialized, onupdatehandler); <br/> target. rem Oveeventlistener (errorevent. error, onerrorhandler); </P> <p> target. checknow (); <br/>}</P> <p>/** <br/> * onerrorhandler <br/> * automatic update error handling <br/> * @ Param errorevent EVT <br/> * @ return void <br/> ***/<br/> private function onerrorhandler (EVT: errorevent): void <br/>{< br/> var target: applicationupdaterui = EVT. currenttarget as applicationupdaterui; </P> <p> target. removeeventlistener (updateevent. ini Tialized, onupdatehandler); <br/> target. removeeventlistener (errorevent. error, onerrorhandler); </P> <p> trace (EVT. tostring (); <br/>}< br/>] --> <br/> </FX: SCRIPT> </P> <p> <FX: declarations> <br/> <! -- Place non-visual elements (such as services and value objects) Here --> <br/> </FX: declarations> </P> <p> <s: layout> <br/> <s: verticallayout verticalalign = "Middle" horizontalalign = "center"/> <br/> </s: layout> </P> <p> <s: Label text = "Hello World" fontsize = "15" fontweight = "bold"/> <br/> <s: label id = "TXT" text = "version update:" fontsize = "15" fontweight = "bold"/> <br/> </S: Drawing wedapplication> <br/>
2. Configure the update. xml file on the server
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <update xmlns = "http://ns.adobe.com/air/framework/update/description/1.0"> <br/> <version> 1.2 </version> <br/> <URL> HTTP: // localhost/air_update/air_versionupdate.air </URL> <br/> <description> <br/> <text XML: lang = "en_us"> air AutoUpdate </text> <br/> <text XML: lang = "zh_cn"> air automatic update </text> <br/> </description> <br/> </update>
PS:
A few notes must be noted.
Requires flex SDK 3.2 to support air 1.5
The version number in XML must match the version number of the specified air program. For example, 1.0 must not be written as 1.00.