ActionScript 3 AS3加载Txt

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3加载Txt相关的知识,希望对你有一定的参考价值。

package  {
	
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	
	public class GetExternalText {

		private var _txtFile:URLLoader;
		private var _txtString:String;

		public function GetExternalText() {
			
		}
		
		public function loadText(txtFile:String):void {
			
			_txtFile = new URLLoader();
			_txtFile.load(new URLRequest(txtFile));
			_txtFile.addEventListener(Event.COMPLETE, onLoadTXT, false, 0, true);
			_txtFile.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true);//missing?
			
			
		}

		
		private function onLoadTXT(evt:Event):void {
			_txtString = evt.target.data;
			//clean up
			_txtFile.removeEventListener(Event.COMPLETE, onLoadTXT);
			_txtFile.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
		}

	
		private function ioErrorHandler(evt:IOErrorEvent):void {
			trace("The following file could not be loaded: " + evt.text);
		}
		
		public function get loadedText():String {
			_txtString ||= "none loaded"
			return _txtString;
		}
	
	}
	
}

以上是关于ActionScript 3 AS3加载Txt的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 AS3:加载外部.txt和.css

ActionScript 3 AS3:图像加载

ActionScript 3 AS3预加载器

ActionScript 3 AS3:XML加载

ActionScript 3 AS3:预加载器

ActionScript 3 AS3:加载XML