Flex中的配置文件存储

相信写代码的人经常会用到的就是,把一些不确定的东西写到一个配置文件里面,这样不用去来回修改代码,只要修改一些配置文件就可以了,flex中也可以这么做,以下是几种方式:
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"/>


转: http://riashanghai.com/zh-hant/node/28

你可能感兴趣的:(java,xml,Flex,Flash)