/ Published in: ActionScript 3
Simple load External text Class input: string for url output: string
Expand |
Embed | Plain Text
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; } } }
You need to login to post a comment.
