importflash.events.Event;
importflash.net.URLLoader;
importflash.net.URLRequest;
importflash.net.URLVariables;
publicclassTxtLoader
{
privatevarsetTxt:Function=null;
publicfunctionTxtLoader()
{
}
publicfunctionloadTxt(fileName:String,setTxt:Function):void{
this.setTxt=setTxt;
varurlRequest:URLRequest=newURLRequest(fileName);
varurlLoader:URLLoader=newURLLoader();
urlLoader.addEventListener(Event.COMPLETE,complete);
urlLoader.load(urlRequest);
}
privatefunctioncomplete(event:Event):void{
varurlLoader:URLLoader=event.currentTargetasURLLoader;
setTxt.call(null,urlLoader.data);
}
}
-----------------调用的方法-------------------------------------------------------------
newTxtLoader().loadTxt('readme.txt',function(txt:String):void{
Alert.show(txt);
});