Home >
Here's a quick tip for anyone developing AIR applications. You may often find scenarios where you need to display metadata about your application inside the application itself, from the application descriptor xml file.
This is especially the case for the application name and version number, but may also be useful for the description and copyright, or any other information that you put in the application descriptor xml file.
You can access the AIR application descriptor file through the NativeApplication.nativeApplication.applicationDescriptor property. This is an xml property, and you can treat it as you would any other XML object in Flex or AIR. However, there is a trick. If you were to try accessing properties directly on this XML object without using any custom namespaces, you would quickly find that you can't access anything.
In order to access the properties within your application descriptor, you need to define the namespace for the XML file. This should match the actual namespace in your application descriptor and AIR runtime/sdk version that you are targeting.
Once you define the namespace, you can access it as you would normally access any XML property.
Below you will find a the code for a simple AIR application that reads all properties from the application descriptor and displays them in a mx:TextArea component.
The following is a sample output, based on the contents of the application descriptor xml file:
___________________________________
Andrew Trice
Principal Architect
Cynergy Systems
http://www.cynergysystems.com
This is especially the case for the application name and version number, but may also be useful for the description and copyright, or any other information that you put in the application descriptor xml file.
You can access the AIR application descriptor file through the NativeApplication.nativeApplication.applicationDescriptor property. This is an xml property, and you can treat it as you would any other XML object in Flex or AIR. However, there is a trick. If you were to try accessing properties directly on this XML object without using any custom namespaces, you would quickly find that you can't access anything.
In order to access the properties within your application descriptor, you need to define the namespace for the XML file. This should match the actual namespace in your application descriptor and AIR runtime/sdk version that you are targeting.
namespace ns = "http://ns.adobe.com/air/application/1.1";
use namespace ns;
Once you define the namespace, you can access it as you would normally access any XML property.
Below you will find a the code for a simple AIR application that reads all properties from the application descriptor and displays them in a mx:TextArea component.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
private function onCreationComplete() : void
{
var xml : XML = NativeApplication.nativeApplication.applicationDescriptor;
namespace ns = "http://ns.adobe.com/air/application/1.1";
use namespace ns;
for each ( var child : XML in xml.children() )
{
output.text += child.name().localName.toString() +
":\n" +
child.toString() +
"\n\n";
}
}
]]>
</mx:Script>
<mx:TextArea
id="output"
width="100%" height="100%"
editable="false" />
</mx:WindowedApplication>
The following is a sample output, based on the contents of the application descriptor xml file:
id:
DescriptorSampleID
filename:
DescriptorSampleFileName
name:
AIR descriptor Sample Name
version:
v 0.01
description:
Sample Description
copyright:
go ahead and copy this
initialWindow:
<initialWindow xmlns="http://ns.adobe.com/air/application/1.1">
<content>main.swf</content>
</initialWindow>
Andrew Trice
Principal Architect
Cynergy Systems
http://www.cynergysystems.com




Facebook Application Development
Thanks for the tip, very neat
That`s 15 minutes of bashing my head against the wall... thanks