Question

So I have a basic application descriptor file for my AIR app. It looks something like this, shortened for sanity:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application xmlns="http://ns.adobe.com/air/application/2.0">
  <version>1.0.10</version>
</application>

Now I want in the application to display the version, but I don't want to have to maintain the version in multiple places, so how can I read that version number from within the application?

Was it helpful?

Solution

Check the following code:

            var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor;
            var ns:Namespace = appXml.namespace(); 
            trace(appXml.ns::version); 

OTHER TIPS

This has changed slightly in recent versions of AIR (AIR version 3.x). Instead of appXml.ns::version, you would instead use appXml.ns::versionNumber.

Note that appXml.ns::versionNumber is an XMLList consisting of a single XML object, so it requires a bit of digging if you want to get to the actual String value:

var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = appXml.namespace();
var appVersion:String = appXml.ns::versionNumber[0].toString();
trace("appVersion", appVersion);

Update, March 17, 2017: At some point, they changed AIR's applicationDescriptor again. The following code is working in AIR 23:

var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:String = appXml.namespace().toString();
var nsArray:Array = ns.split("/");
var appVersion:Number = nsArray[nsArray.length - 1];
trace("appVersion:", appVersion); // appVersion: 23.0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top