Reputation: 11054
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?
Upvotes: 3
Views: 1620
Reputation: 1339
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
Upvotes: 7
Reputation: 5308
Check the following code:
var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = appXml.namespace();
trace(appXml.ns::version);
Upvotes: 6