Earlier today a subscriber on the AIR with HTML and JS listserv asked about how one could get the current version of an AIR application from within the application itself. AIR stores the version number in the application.xml file. This is a free-form value that can be anything (number, string, etc.) A quick Google search turned out this perfect tip: Quick Tip: Display Application Version in your AIR App This worked, but I wanted to mock up a quick HTML version. Unfortunately dealing with XML in JavaScript kind of makes me want to throw up a little. I think ColdFusion has got me spoiled. But once I figured out the syntax (thank you again W3 Schools) I was able to whip up the following demo.
<!--
Credit goes to Joseph Labrecque: http://inflagrantedelicto.memoryspiral.com/2009/02/quick-tip-display-application-version-in-your-air-app/
-->
<html>
<head>
<title>New Adobe AIR Project</title>
<script type="text/javascript" src="lib/air/AIRAliases.js"></script>
<script>
function init() {
var appdesc = air.NativeApplication.nativeApplication.applicationDescriptor;
parser=new DOMParser();
xmlDoc=parser.parseFromString(appdesc,"text/xml");
version = xmlDoc.getElementsByTagName("version")[0];
air.trace(version.textContent);
document.getElementById("version").innerText = version.textContent;
}
</script>
</head>
<body onload="init()">
<h1>KnowThyself</h1>
<p>
Hello, you are running version <span id="version"></span> of the application.
</p>
</body>
</html>
The application simply loads up the XML via the NativeApplication object. This is a string, and while we could parse it using regex, I went ahead and did it the "XML" way and converted it to a proper object. Once done it is pretty trivial to get the version. (Again, once you remind yourself how XML stuff is manipulated in JavaScript.) When the application loads, whatever you have in your application.xml for version will show up in the span.