Flex txt 텍스트 읽기

1297 단어 .netFlexFlash
인스턴스는 첨부 파일 참조
main.mxml

	<mx:Script>
		<![CDATA[
			public function init():void {
				new TxtLoader().loadTxt('readme.txt', function(txt:String):void {
						showTxt.text = txt;
					});
			}
		]]>
	</mx:Script>

	<mx:TextArea id="showTxt" width="100%" height="100%"/>

TxtLoader.as

package {
	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);
		}
	}
}

좋은 웹페이지 즐겨찾기