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

发布于 2024-10-13 00:37:24 字数 503 浏览 5 评论 0原文

当不同的值发生更改时,我在尝试使用动作脚本加载不同的文件时遇到问题。我目前正在使用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";
 }

所以我希望在选择不同的值时加载不同的文本文件,但我似乎无法得到它工作了。任何人都可以给我任何解决方案吗?非常感谢。提前致谢。

I am having trouble trying to use actionscript to load different files when different values are changed. I am currently using a tilelist and they have different values so the code is something like this: (the title is just there, non-related)

 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";
 }

So I want different text files to be loaded when different value is selected but I cannot seem to get it working. Anybody can give me any solutions? Much appreciated. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2024-10-20 00:37:24

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

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”的属性中找到数据。

Here is a simple example for loading external text file:

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;                
}

In this example, i use a URLLoader object. This is a native ActionScript3 object taht let you download external ressources.
Loading an external ressource in AS3 is an asynchronous process, that's why you must listen to the COMPLETE event.
Once loaded, you will find your data inside the property named 'data' of your URLLoader object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文