我一直想一個文本文件加載到一個字符串變量。該文本文件名爲text.txt
含successful
。下面的代碼:在AS3中,一個文本文件加載到一個字符串
public class Main extends Sprite
{
private var text:String = "text";
private var textLoader:URLLoader = new URLLoader();
public function Main() {
textLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
trace("Before 1: " + text); //output: text
trace("Before 2: " + e.target.data); //output: successful
text = e.target.data;
trace("After 1: " + text); //output: successful - yay!!! it worked
}
textLoader.load(new URLRequest("text.txt"));
trace("After 2: " + text); //output: text - what??? nothing happened??? but it just worked
}
}
輸出:
After 2: text Before 1: text Before 2: successful After 1: successful
所以,我應該怎麼辦呢? –
@DleanJeans我更新了我的答案:) – axelduch
但可以和我怎麼得到它(加載文本)以後? –