Application{font-size:12px;}
Application{fontSize:14px;}
import mx.rpc.events.ResultEvent;
import mx.events.FlexEvent;
import mx.rpc.http.HTTPService;
private var txtLoader:HTTPService=new HTTPService();
//加载文本代码如下
private function loadTxt(evt:FlexEvent):void
{
txtLoader.url="test1.txt";//文件路径
txtLoader.resultFormat="text";//结果的格式是纯文本
txtLoader.addEventListener(ResultEvent.RESULT,resultHandler);
txtLoader.send();
}
private function resultHandler(evt:ResultEvent):void
{
myTxt.text=evt.target.lastResult;//这里为文本控件赋值
}
]]>
import mx.events.FlexEvent;
private var loader:URLLoader=new URLLoader();
private function loadTxt(evt:FlexEvent):void
{
loader.addEventListener(Event.COMPLETE,handleData);
loader.load(new URLRequest("test1.txt"));
}
//数据加载完毕,为文本赋值
private function handleData(evt:Event):void
{
myTxt.text=evt.target.data;//URLLoader对象的data域
}
]]>
Application{fontSize:14px;}
Application{fontSize:12px;color:#ff0000;}
import mx.rpc.events.ResultEvent;
import mx.events.FlexEvent;
import mx.rpc.http.HTTPService;
private var svc:HTTPService=new HTTPService();
private function loadVal(evt:FlexEvent):void
{
svc.url="test2.txt";
svc.resultFormat="flashvars";//结果格式-值对
svc.addEventListener(ResultEvent.RESULT,handleResult);
svc.send();
}
private function handleResult(evt:ResultEvent):void
{
lbl.text=svc.lastResult.lbl;
combox.dataProvider=svc.lastResult.jobs.split(",");
}
]]>
Application{font-size:14px;color:green;}
import mx.events.FlexEvent;
import flash.net.URLLoader;
private var loader:URLLoader=new URLLoader();
private function loadVal(evt:FlexEvent):void
{
loader.addEventListener(Event.COMPLETE,handleComplete);
loader.load(new URLRequest("test2.txt"));
}
private function handleComplete(evt:Event):void
{
var value:URLVariables=new URLVariables(evt.target.data);
lbl.text=value.lbl;
combox.dataProvider=value.jobs.split(",");
}
]]>