Featured Post

Twitter Updates for 2008-03-27

listening to Adam Lehman talk about Live Chat and CF/Flex/Blaze DS over my lunch hour. # Went downtown over lunch and picked up boss’ notebook from repair, seems to be working great now. Need to take it to SB and test on hotspot # @raown Mozy looking good # mxml component visible="false" yet still takes up space eq to visible component. How have you approached this problem? # @reboog711 thanks I wasn’t sure what property to look for! I will tweet back in a few about it. # @reboog711 that’s more better! Thanks # Powered by Twitter Tools.

Read More

Follow @dougrdotnet on Twitter

Using NativeApplication To Get App Version

Posted by dougr | Posted in AIR, ActionScript, Cairngorm, Flex | Posted on 24-07-2009 | 1,308 views

Tags: , , , ,

0

This is a nice little gem I wanted to share. I needed to display the current version of my application in the startup screen, when the user launches the app. I’ve already been updating this as I push releases to my update server where my updater xml file is located. At first I was going to just do a request for that xml document but then thought I’ve already got the version locally in the app.xml file, why not get it from there and not have to have the request.

I’m using Cairngorm so I wrote a command class to do this for me.

package com.dougrdotnet.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.dougrdotnet.model.StatusModelLocator;

	import flash.desktop.NativeApplication;

	public class GetAppXMLVersionCommand implements ICommand
	{
		private var statusModel:StatusModelLocator = StatusModelLocator.getInstance();
		public function execute(event:CairngormEvent):void
		{
		   var descriptor:XML = NativeApplication.nativeApplication.applicationDescriptor;
		   var ns:Namespace = descriptor.namespace();
		   var version:String = descriptor.ns::version;
		   statusModel.version = version;
		}

	}
}

What i’ve done is use the NativeApplication class’ applicationDescriptor property to get the XML from app.xml. I set a variable to hold the namespace value from the descriptor xml. Then I go in and get the version node using descriptor.ns::version. Then, in this case, I am assigning the version string to a Model variable so that I can use it wherever that model singleton exists. Certainly, this method could simply return version to supply the value to the caller.

Write a comment