Archive for October, 2010
Slides and source code of my Adobe MAX 2010 presentation
Adobe MAX 2010 is over and I’m heading back to Poland. Before I get on the plane I wanted to post my presentation deck and the source code of a demo app that I used to cover the DI frameworks. I also hope to post the session recording as soon as it gets to Adobe TV. BTW this years MAX was really awesome!
Building NativeApplicationUpdater custom UI
After I published the NativeApplicationUpdater library I received a lot of questions how to display a UI showing download and install progress. Unfortunately NAU doesn’t come with a built-in UI yet
So I decided to put together this short blog post to explain how you can build it yourself. Below you can see how the demo app with the custom UI looks (project source code is available here in SVN):

Below is snippet of code that you can examine to better understand how to build your own updater UI:
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:updater="http://updater.riaspace.com/"> <fx:Script> <![CDATA[ import air.update.events.DownloadErrorEvent; import air.update.events.StatusUpdateEvent; import air.update.events.UpdateEvent; import mx.controls.Alert; [Bindable] protected var downlaoding:Boolean = false; protected function isNewerFunction(currentVersion:String, updateVersion:String):Boolean { // Example of custom isNewerFunction function, it can be omitted if one doesn't want // to implement it's own version comparison logic. Be default it does simple string // comparison. return true; } protected function updater_errorHandler(event:ErrorEvent):void { Alert.show(event.text); } protected function btnCheckNow_clickHandler(event:MouseEvent):void { // First initialize NativeApplicationUpdater updater.initialize(); } protected function updater_initializedHandler(event:UpdateEvent):void { // When NativeApplicationUpdater is initialized you can call checkNow function updater.checkNow(); } protected function updater_updateStatusHandler(event:StatusUpdateEvent):void { if (event.available) { // In case update is available prevent default behavior of checkNow() function // and switch to the view that gives the user ability to decide if he wants to // install new version of the application. event.preventDefault(); currentState = "updaterView"; } else { Alert.show("Your application is up to date!"); } } protected function btnYes_clickHandler(event:MouseEvent):void { // In case user wants to download and install update display download progress bar // and invoke downloadUpdate() function. downlaoding = true; updater.addEventListener(DownloadErrorEvent.DOWNLOAD_ERROR, updater_downloadErrorHandler); updater.addEventListener(UpdateEvent.DOWNLOAD_COMPLETE, updater_downloadCompleteHandler); updater.downloadUpdate(); } protected function btnNo_clickHandler(event:MouseEvent):void { currentState = "mainView"; } private function updater_downloadCompleteHandler(event:UpdateEvent):void { // When update is downloaded install it. updater.installUpdate(); } private function updater_downloadErrorHandler(event:DownloadErrorEvent):void { Alert.show("Error downloading update file, try again later."); } ]]> </fx:Script> <s:states> <s:State name="mainView"/> <s:State name="updaterView"/> </s:states> <fx:Declarations> <updater:NativeApplicationUpdater id="updater" updateURL="http://riaspace.com/native-application-updater/update-1.1.xml" isNewerVersionFunction="{isNewerFunction}" initialized="updater_initializedHandler(event)" updateStatus="updater_updateStatusHandler(event)" error="updater_errorHandler(event)" downloadError="updater_errorHandler(event)" updateError="updater_errorHandler(event)" /> </fx:Declarations> <s:Button id="btnCheckNow" label="Check for updates" includeIn="mainView" horizontalCenter="0" verticalCenter="0" click="btnCheckNow_clickHandler(event)"/> <s:HGroup verticalCenter="0" includeIn="updaterView" horizontalCenter="0" verticalAlign="top"> <s:BitmapImage source="@Embed(source='/assets/icon128.png')" /> <s:VGroup width="100%" horizontalAlign="center"> <s:Label text="New version ({updater.updateVersion}) is available." /> <s:Label text="Do you want to download it and install?" /> <mx:ProgressBar id="prgBar" source="{updater}" label="Downloading %3%" visible="{downlaoding}" /> <s:HGroup> <s:Button id="btnYes" label="Yes" click="btnYes_clickHandler(event)" /> <s:Button id="btnNo" label="No" click="btnNo_clickHandler(event)" /> </s:HGroup> </s:VGroup> </s:HGroup> </s:WindowedApplication>
NativeApplicationUpdater version 0.4 released!
I just posted a new version (0.4) of the NativeApplicationUpdater library. It fixes some minor bugs and removes a workaround for the different URLStream events sequence between Win OS and other OSes.
Stay tuned for my next post that explains how to build NAU custom UI.

