FLEX中讀取XML檔案
阿新 • • 發佈:2019-01-03
有時候我們可能需要在FLEX中操作XML檔案.
可以在Flex客戶端工程的資原始檔夾asserts裡面新增.asserts/config/text.xml 如下:
如果說我們想在容器預初始化的時候,就讀取出XML的內容。preinitialize="application1_preinitializeHandler(event)"<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>
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 = [email protected];
var normManageTitle:String = [email protected];
var quotaManageTitle:String = xml.conf[email protected];
var quotaMethodConfigTitle:String = [email protected];
//基礎配置2
var baseDatApplyTitle:String = [email protected];
var fileBatchImpTitle:String = [email protected];
var dataApplyTitle:String = [email protected];
//基礎配置3
var cityColligateQuotaTitle:String = [email protected];
var citySingleQuotaChangeTitle:String = [email protected];
var cityColligateScoreTitle:String = [email protected];
}
}
恩...這樣就可以取得配置檔案中的title的值。