AIR ConnectionManager + UpdateManager
Download everythingflexairlib.swc
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.
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.
<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.
<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>
