<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/09/air-tip-accessing-application-descriptor.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2008://34.33363-</id>
  <updated>2009-11-18T11:07:39Z</updated>
  <title>Comments for AIR Tip:  Accessing Application Descriptors (http://www.insideria.com/2008/09/air-tip-accessing-application-descriptor.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.33363</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/09/air-tip-accessing-application-descriptor.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=33363" title="AIR Tip:  Accessing Application Descriptors" />
    <published>2008-09-11T00:47:37Z</published>
    <updated>2008-09-11T01:55:51Z</updated>
    <title>AIR Tip:  Accessing Application Descriptors</title>
    <summary>Here&apos;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 tip will show you exactly how to access application descriptor information.</summary>
    <author>
      <name>Andrew Trice</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[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.   
<br/><br/>
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. 
<br/><br/>
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.
<br/><br/>
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.
<br/><br/>
<code>namespace ns = "http://ns.adobe.com/air/application/1.1";<br/>
use namespace ns;
</code>
<br/><br/>
Once you define the namespace, you can access it as you would normally access any XML property.   <br/><br/>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.
<br/><br/>
<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> <code language="perl">
<pre> &lt;?xml <span class="category2">version</span>="<span class="quote">1.0</span>" encoding="<span class="quote">utf-8</span>"?&gt;
&lt;mx:WindowedApplication 
   xmlns:mx="<span class="quote">http://www.adobe.com/2006/mxml</span>" 
   layout="<span class="quote">absolute</span>"
   creationComplete="<span class="quote">onCreationComplete()</span>"&gt;
   
   &lt;mx:Script&gt;
      &lt;![CDATA[
         
         <span class="category1">private</span> <span class="category1">function</span> onCreationComplete() : <span class="category1">void</span>
         {
             <span class="category1">var</span> xml : <span class="category2">XML</span> = NativeApplication.nativeApplication.applicationDescriptor;
             
             namespace ns = "<span class="quote">http://ns.adobe.com/air/application/1.1</span>";
             use namespace ns;
             
             <span class="category1">for</span> each ( <span class="category1">var</span> child : <span class="category2">XML</span> <span class="category1">in</span> xml.children() )
             {
                 output.<span class="category2">text</span> += child.<span class="category2">name</span>().localName.<span class="category2">toString</span>() + 
                                "<span class="quote">:\n</span>" + 
                                child.<span class="category2">toString</span>() + 
                                "<span class="quote">\n\n</span>";
              }
          }
         
      ]]&gt;
   &lt;/mx:Script&gt;
   
   &lt;mx:TextArea 
      id="<span class="quote">output</span>"
      <span class="category2">width</span>="<span class="quote">100%</span>" <span class="category2">height</span>="<span class="quote">100%</span>" 
      editable="<span class="quote">false</span>" /&gt;
   
&lt;/mx:WindowedApplication&gt;</pre>
</code>
 
</div></div> 
<br/>
The following is a sample output, based on the contents of the application descriptor xml file:<br/><br/>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"><pre><code>id:
DescriptorSampleID

filename:
DescriptorSampleFileName

name:
AIR descriptor Sample Name

version:
v 0.01

description:
Sample Description

copyright:
go ahead and copy this

initialWindow:
&lt;initialWindow xmlns="http://ns.adobe.com/air/application/1.1"&gt;
  &lt;content&gt;main.swf&lt;/content&gt;
&lt;/initialWindow&gt;
</code></pre></div></div>


___________________________________<br/>
<strong>Andrew Trice</strong><br/>
Principal Architect<br/>
<a href="http://www.cynergysystems.com" target="_blank">Cynergy Systems<br/>
http://www.cynergysystems.com</a><br/>

]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.33363-comment:2042545</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.33363" type="text/html" href="http://www.insideria.com/2008/09/air-tip-accessing-application-descriptor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/09/air-tip-accessing-application-descriptor.html#comment-2042545" />
    <title>Comment from julien on 2008-09-10</title>
    <author>
        <name>julien</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Thanks for the tip, very neat</p>]]>
    </content>
    <published>2008-09-11T04:42:51Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.33363-comment:2192021</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.33363" type="text/html" href="http://www.insideria.com/2008/09/air-tip-accessing-application-descriptor.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/09/air-tip-accessing-application-descriptor.html#comment-2192021" />
    <title>Comment from alin on 2009-11-18</title>
    <author>
        <name>alin</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>That`s 15 minutes of bashing my head against the wall... thanks</p>]]>
    </content>
    <published>2009-11-18T11:07:34Z</published>
  </entry>

</feed
