如何从AS / MXML代码中的AIR清单文件中读取

时间:2011-01-25 16:42:53

标签: flex air manifest

Flash Builder为每个AIR项目生成了AppName-app.xml描述符。那里有许多设置,值,包括下面。是否可以在代码中读取这些内容而无需在运行时显式加载此XML(即使这样我不知道是否可能)?也许是Loader.info或类似的?

<!-- The name that is displayed in the AIR application installer. 
         May have multiple values for each language. See samples or xsd schema file. Optional. -->
    <name>ffff</name>

    <!-- A string value of the format <0-999>.<0-999>.<0-999> that represents application version which can be used to check for application upgrade. 
    Values can also be 1-part or 2-part. It is not necessary to have a 3-part value.
    An updated version of application must have a versionNumber value higher than the previous version. Required for namespace >= 2.5 . -->
    <versionNumber>1</versionNumber>


    <!-- Description, displayed in the AIR application installer.
         May have multiple values for each language. See samples or xsd schema file. Optional. -->
    <!-- <description></description> -->

    <!-- Copyright information. Optional -->
    <!-- <copyright></copyright> --> 

2 个答案:

答案 0 :(得分:1)

您还可以执行以下操作:

var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = appXml.namespace();
title = appXml.ns::name + " " + appXml.ns::versionNumber;

因此,您不需要在代码中对命名空间进行硬编码。

答案 1 :(得分:0)

您尝试阅读的内容称为“应用程序描述符”。

它是XML,但它很容易阅读:

var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor;

namespace ns = "http://ns.adobe.com/air/application/2.5";
use namespace ns;

Alert.show("appId: " + appXml.id);
Alert.show("version: " + appXml.versionNumber);
Alert.show("filename: " + appXml.filename);

请注意,我将命名空间设置为我正在使用的命名空间。您应该确保使用应用程序描述符的根目录中定义的命名空间。

祝你好运!