Using NativeApplication To Get App Version
Posted by dougr | Posted in AIR, ActionScript, Cairngorm, Flex | Posted on 24-07-2009
Tags: ActionScript, AIR, Cairngorm, Flex, linkedin
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.











