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

当更改不同的值时,我在尝试使用actionscript加载不同的文件时遇到问题。我目前正在使用tilelist,它们有不同的值,所以代码是这样的:(标题就在那里,不相关)
 if (startTileList.selectedItem.value == 1)
 {
  //textFile1 load here
  txtTitle.text = "History";
 }
 else if (startTileList.selectedItem.value == 2)
 {
  //textFile2 load here
  txtTitle.text = "Features";
 }
 else if (startTileList.selectedItem.value == 3)
 {
  //textFile3 load here
  txtTitle.text = "Gallery";
 }
所以我希望在选择不同的值时加载不同的文本文件,但我似乎无法使其正常工作。有谁能给我任何解决方案?非常感激。提前致谢。     
已邀请:
这是一个加载外部文本文件的简单示例:
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中加载外部资源是一个异步过程,这就是您必须侦听COMPLETE事件的原因。 加载后,您将在URLLoader对象的名为“data”的属性中找到您的数据。     

要回复问题请先登录注册