3

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?

invertedSpear
  • 10,864
  • 5
  • 39
  • 77

2 Answers2

7

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
T Graham
  • 1,329
  • 10
  • 14
  • I can't believe it took upwards of an hour to figure out how to do this. Flash has its strong points but OMG. XML in Flash is an effing nightmare. – ericsoco Jul 25 '14 at 05:55
  • I also can't believe that Adobe's documentation uses the deprecated version as an example over 3 years later. – Dave Walker Jan 30 '17 at 12:08
6

Check the following code:

            var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor;
            var ns:Namespace = appXml.namespace(); 
            trace(appXml.ns::version); 
Cornel Creanga
  • 5,311
  • 1
  • 22
  • 28