AIR ConnectionManager + UpdateManager
The AIR ConnectionManager and UpdateManager classes work perfectly well individually however, I recommend that they are used together to ensure that your application will stay up to date by checking for updates when an Internet connection is present.
There are 2 examples below.
The first creates an instance of the ConnectionManager and an instance of the UpdateManager with the UpdateManager’s second constructor argument set to false. This will prevent the UpdateManager from automatically checking for an update on creation. Next a Button component is added with the enabled property bound to the ConnectionManager’s isConnected property. This will ensure that the user can only check for an available update when an Internet connection exists.
- <?xml version="1.0" encoding="utf-8"?>
- <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="absolute">
- <mx:Script>
- <![CDATA[
- import com.everythingflex.air.managers.UpdateManager;
- import com.everythingflex.air.managers.ConnectionManager;
- [Bindable]
- private var cm:ConnectionManager = new ConnectionManager();
- private var um:UpdateManager = new UpdateManager("http://www.yourdomain.com/appName/version.xml",false);
- ]]>
- </mx:Script>
- <mx:Label text="Hello World!" fontSize="20"
- horizontalCenter="0" y="120"/>
- <mx:Button label="Check for Update"
- click="um.checkForUpdate()"
- enabled="{cm.isConnected}"
- horizontalCenter="0" y="160"/>
- </mx:WindowedApplication>
The second example sets up an event listener within the init() function which will fire whenever the connection status changes. The event handler (the connectionChange() function) will call the UpdateManagers checkForUpdate() function if the isConected property is true.
- <?xml version="1.0" encoding="utf-8"?>
- <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="absolute" creationComplete="init()">
- <mx:Script>
- <![CDATA[
- import com.everythingflex.air.managers.UpdateManager;
- import com.everythingflex.air.managers.ConnectionManager;
- [Bindable]
- private var cm:ConnectionManager = new ConnectionManager();
- private var um:UpdateManager = new UpdateManager("http://www.everythingflex.com/AIR/UMTest/version.xml",false);
- private function init():void{
- cm.addEventListener(StatusEvent.STATUS,connectionChange);
- }
- private function connectionChange(event:StatusEvent):void{
- if(event.target.isConnected)um.checkForUpdate();
- }
- ]]>
- </mx:Script>
- <mx:Label text="Hello World!" fontSize="20"
- horizontalCenter="0" y="120"/>
- <mx:Button label="Check for Update"
- click="um.checkForUpdate()"
- enabled="{cm.isConnected}"
- horizontalCenter="0" y="160"/>
- </mx:WindowedApplication>




March 21st, 2008 at 1:41 pm
I have to say I love these classes, and thanks! I do have a question though- is the source for the UpdateManager available, or do you have any plans to make it available? For example, I would like to do things like tweak the Alert message.
Thanks again!
March 21st, 2008 at 1:43 pm
Or inform the user that an update is about to be installed (in the case of a forced update)!
March 22nd, 2008 at 3:53 pm
Yes, I will be moving the source to google code shortly. The source is also in my AIR book at:
http://blog.everythingflex.com/2008/03/19/get-a-free-flex-book/
June 9th, 2008 at 10:29 am
What about the users permissions? Can a not-administrator user download the xml file for the check? and update the application?
Thanks
June 9th, 2008 at 10:45 am
The XML file is read and parsed by the ConnectionManager. It should not be a problem for a non admin as it simply requires Internet access. The download of the new AIR install file and install could certainly have permission issues as it does require install privileges.
July 17th, 2008 at 3:32 am
I have a problem: don’t run correcty.
my problem is:
my app descriptor’s version field is that:
–AIR-app.xml–
v1
and I have a version.xml file like that:
—-
when I execute this code:
var um : UpdateManager = new UpdateManager(”http://www.mywebsitecom/AIR_appDescriptors/version.xml”, false);
um.checkForUpdate();
returns true, when the version field are de same, and this means that there isn’t any update. What I do wrong?
Exuse my wrong english please, I write from spain…
July 17th, 2008 at 3:34 am
excuse me:
AIR-app.xml version field is : v1
and version.xml is :
when version is v1
July 17th, 2008 at 3:35 am
link on version.xml is: http://sgeno.com/AIR_appDescriptors/version.xml
July 17th, 2008 at 4:51 am
So, you would need to pass http://sgeno.com/AIR_appDescriptors/version.xml into the UpdateManager constructor:
var um : UpdateManager = new UpdateManager(”http://sgeno.com/AIR_appDescriptors/version.xml”, false);
Also, it appears that the path to your downloadLocation defined within http://sgeno.com/AIR_appDescriptors/version.xml is incorrect as it is currently pointing to a fake location.
July 17th, 2008 at 5:31 am
yes, I have like you say:
var um : UpdateManager = new UpdateManager(”http://sgeno.com/AIR_appDescriptors/version.xml”, false);
um.checkForUpdate();
this is the correct code I have in my program
July 17th, 2008 at 5:33 am
why you say that my downloadLocation defined within http://sgeno.com/AIR_appDescriptors/version.xml is incorrect ? I can go and see xml file!?
July 17th, 2008 at 7:56 am
You currently have the downloadLocation property of the version.xml file set to:
http://www.yourdomain.com/AIR/UMTest/UM.air
Unless you actually own the domain name yourdomain.com, I suspect this is not the correct path to teh downloadLocation of your air file.
July 17th, 2008 at 11:33 am
can I change the text of update information alert ?
July 17th, 2008 at 1:04 pm
You can change the text that appears by adjusting the message property of your version.xml file.