有时候我们可能需要在FLEX中操作XML文件.
可以在Flex客户端工程的资源文件夹asserts里面添加.asserts/config/text.xml 如下:
<configuration>
<config>
<con1 title="配置1"/>
<con2 title="配置2"/>
<con3 title="配置3"/>
<con4 title="配置4"/>
</config>
<apply>
<app1 title="配置1"/>
<app2 title="配置2" />
<app3 title="配置13"/>
</apply>
<appraise>
<se1 title="配置1"/>
<se2 title="配置2"/>
<se3 title="配置3"/>
</appraise>
</configuration>
如果说我们想在容器预初始化的时候,就读取出XML的内容。preinitialize="application1_preinitializeHandler(event)"
var loader:URLLoader=new URLLoader();
var request:URLRequest=new URLRequest("assets/config/test.xml");
loader.load(request);
loader.addEventListener(Event.COMPLETE,loadComplete);
private function loadComplete(event:Event):void
{
if(loader.data)
{
xml=XML(loader.data);
//基础配置1
var baseItemManageTitle:String = xml.config.conf1.@title;
var normManageTitle:String = xml.config.conf2.@title;
var quotaManageTitle:String = xml.config.conf3.@title;
var quotaMethodConfigTitle:String = xml.config.conf4.@title;
//基础配置2
var baseDatApplyTitle:String = xml.apply.app1.@title;
var fileBatchImpTitle:String = xml.apply.app2.@title;
var dataApplyTitle:String = xml.apply.app3.@title;
//基础配置3
var cityColligateQuotaTitle:String = xml.appraise.se1.@title;
var citySingleQuotaChangeTitle:String = xml.appraise.se2.@title;
var cityColligateScoreTitle:String = xml.appraise.se3.@title;
}
}
恩...这样就可以取得配置文件中的title的值。