欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

flex actionScript读取文件示例代码

程序员文章站 2022-03-21 23:27:40
import flash.events.event; import flash.net.urlloader; import flash.net.urlre...
 import flash.events.event;
 import flash.net.urlloader;
 import flash.net.urlrequest;
 import flash.net.urlvariables;
 
 public class txtloader
 {
 private var settxt:function = null;
 public function txtloader()
 {
 }
 
 public function loadtxt(filename:string, settxt:function):void {
  this.settxt = settxt;
  var urlrequest:urlrequest = new urlrequest(filename);
  var urlloader:urlloader = new urlloader();
  urlloader.addeventlistener(event.complete, complete);
  urlloader.load(urlrequest);
 }
 
 private function complete(event:event):void {
  var urlloader:urlloader = event.currenttarget as urlloader;
  settxt.call(null, urlloader.data);
 }
 }

-----------------调用的方法-------------------------------------------------------------   

new txtloader().loadtxt('readme.txt', function(txt:string):void { 

         alert.show( txt); 

    });