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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.