actionscript-3 - Flash AS3 读取文本文件

标签 actionscript-3 file load

我只需要从我的计算机或网站读取文本文件。我已经尝试了一切,但到目前为止没有任何效果。它应该非常简单,只需从网站读取文本文件,例如 http://foo.com/foo.txt/ ,但我已经尝试了所有方法,但我在 Google 上看到的任何方法都无法正常工作。我不在乎如何解决问题,只要我能做到。

最佳答案

要读取文件的内容,只需使用URLLoader:

// Define the path to the text file.
var url:URLRequest = new URLRequest("file.txt");

// Define the URLLoader.
var loader:URLLoader = new URLLoader();
loader.load(url);

// Listen for when the file has finished loading.
loader.addEventListener(Event.COMPLETE, loaderComplete);
function loaderComplete(e:Event):void
{
    // The output of the text file is available via the data property
    // of URLLoader.
    trace(loader.data);
}

对于其他域上的内容,您需要托管一个跨域文件才能加载文本文件。

关于actionscript-3 - Flash AS3 读取文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15400433/

相关文章:

mysql - LOAD DATA INFILE 和 LINES TERMINATED 错误

java - 同步游戏(MMORPG)客户端和服务器之间的时间/事件?

flash - 如何在 AS3 中设置 swf 的宽度和高度?

flash - 如何在ActionScript 3中删除/GC对象?

javascript - 面向对象的Javascript,与Flash的通信

php - 为什么 auto_prepend_file 在 php 的交互模式下不起作用?

c - __FILE__ 宏显示完整路径

python - win32file.createFile "The System cannot find the specified path"

file - NTFS $MFT 文件可以有子记录吗?

jquery - 使用特定 div 时,.load jquery 函数不起作用