【发布时间】:2014-12-31 14:53:49
【问题描述】:
我一直在尝试将文本文件加载到字符串变量中。名为text.txt 的文本文件包含successful。代码如下:
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
【问题讨论】:
标签: actionscript-3 asynchronous