闪存AS3读取文本文件 [英] Flash AS3 Read Text File
问题描述
我只是需要从我的计算机或网站阅读的文本文件。我用尽了一切,并没有什么迄今已奏效。它应该是非常简单,只需要读取文本文件从网站,如 http://foo.com/foo。 TXT / ,但我已经尝试了一切,并没有什么我看到的谷歌来,甚至接近正常工作。我不在乎我得到的问题解决了,只要我能做到这一点。
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. I don't care how I get the problem solved, as long as I can do it.
推荐答案
要读取一个文件的内容,只需要使用的URLLoader
:
To read the content of a file, just use a 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.
这篇关于闪存AS3读取文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!