为了保障原创作者在本站发表文章的利益, 并维护本站原创的精神, 特声明: RIAShanghai对有以下任何情况之一的文章将不通知作者并直接进行快意删除:
- 非原创, 或者原创但一文多发;
- 各种形式的广告与吹擂;
- 不符合本站文章格式.
欢迎各位读者监督. 谢谢合作. 另: 作为Adobe正式的UG, 我们将把Adobe不定期分发的软件,书籍及各种纪念品赠送给发文活跃的作者, 共同进步.
Those who have Java experience should be very familiar with Java's configuration storage mechanism. You throw your configuration into an XML file and load it from the JAR file. However, in Flex, there is no way to read resources other than sprites or graphics from SWC/SWF files.
How do you store your configuration data in Flex? Basically, there are four ways:
1. Store configuration in static constants
e.g.,
public class MyApp {
public static const config:XML = <config><property name="id" value="1"/></config>;
}
2. Store configuration in a resource bundle
e.g.:
// MyApp_locale.properties:
myapp_cofig: <config><property name="id" value="1"/></config>;
Technically, it's the same with method 1 since the compiler will ultimately convert your resource bundle to a class.
3. Store configuration in metadata
[MyConfig(name="id", value="1")]
public class MyApp { ... }
Then at the runtime, you can use flash.utils.describeType(new MyApp()) to obtain the metadata in XML format.
Note: You need to append -keep-as3-metadata+=MyConfig to your compiler options. Otherwise, the compiler will ignore your metadata.
4. Probably the best way - <mx:XML>
<mx:XML id="xmlModulesConfig" source="modules.xml"/>