简体   繁体   English

Flash AS3读取文本文件

[英]Flash AS3 Read Text File

I simply need to read a text file from my computer, or a website. 我只需要从计算机或网站上读取文本文件即可。 I've tried everything, and nothing so far has worked. 我已经尝试了一切,但到目前为止没有任何效果。 It should be extremely simple, just reading a text file from a website, like http://foo.com/foo.txt/ , but I've tried everything, and nothing I have seen on Google comes even close to working. 它应该非常简单,只需从网站(例如http://foo.com/foo.txt/)读取文本文件,但我已经尝试了所有方法,而在Google上看到的任何内容都几乎无法正常工作。 I don't care how I get the problem solved, as long as I can do it. 只要能做到,我就不在乎如何解决问题。

To read the content of a file, just use a URLLoader : 要读取文件的内容,只需使用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);
}

For stuff on another domain, you will need to have a crossdomain file hosted to be able to load the text file. 对于另一个域上的内容,您将需要托管一个跨域文件才能加载该文本文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM