Flash 选择不同的值时加载不同的外部文本文件

Flash 选择不同的值时加载不同的外部文本文件,flash,actionscript-3,tilelist,Flash,Actionscript 3,Tilelist,当不同的值发生更改时,尝试使用actionscript加载不同的文件时遇到问题。我目前正在使用tilelist,它们有不同的值,所以代码是这样的:(标题就在那里,不相关) 所以我希望在选择不同的值时加载不同的文本文件,但我似乎无法让它工作。有人能给我任何解决办法吗?非常感谢。提前感谢。下面是一个加载外部文本文件的简单示例: var textField:TextField = new TextField(); //URLLoader used for loading an external fi

当不同的值发生更改时,尝试使用actionscript加载不同的文件时遇到问题。我目前正在使用tilelist,它们有不同的值,所以代码是这样的:(标题就在那里,不相关)


所以我希望在选择不同的值时加载不同的文本文件,但我似乎无法让它工作。有人能给我任何解决办法吗?非常感谢。提前感谢。

下面是一个加载外部文本文件的简单示例:

var textField:TextField = new TextField();

//URLLoader used for loading an external file           
var urlLoader : URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
//add to URLLoader a complete event listener (when the file is loaded)
urlLoader.addEventListener(Event.COMPLETE, loadingComplete);


//your application logic
var textURL : String;
if (true) {
    textURL = "http://www.foo.com/text1.txt";
}else{
    textURL = "http://www.foo.com/text2.txt";
}

//Tell to URLLoader to load the file
urlLoader.load(new URLRequest(textURL));

function loadingComplete(e:Event):void{
    //remove the listener
    urlLoader.removeEventListener(Event.COMPLETE, loadingComplete);
    //update the text field with the loaded data
    textField.text = urlLoader.data;                
}
在本例中,我使用一个URLLoader对象。这是一个本机ActionScript3对象,用于下载外部资源。 在AS3中加载外部ressource是一个异步过程,因此必须侦听完整事件。
加载后,您将在URLLoader对象名为“data”的属性中找到数据。

请在代码中添加您正在执行的操作的注释。仅仅发布解决方案并不能解释问题。
var textField:TextField = new TextField();

//URLLoader used for loading an external file           
var urlLoader : URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
//add to URLLoader a complete event listener (when the file is loaded)
urlLoader.addEventListener(Event.COMPLETE, loadingComplete);


//your application logic
var textURL : String;
if (true) {
    textURL = "http://www.foo.com/text1.txt";
}else{
    textURL = "http://www.foo.com/text2.txt";
}

//Tell to URLLoader to load the file
urlLoader.load(new URLRequest(textURL));

function loadingComplete(e:Event):void{
    //remove the listener
    urlLoader.removeEventListener(Event.COMPLETE, loadingComplete);
    //update the text field with the loaded data
    textField.text = urlLoader.data;                
}