Flash AS3 Read Text File

こ雲淡風輕ζ 提交于 2019-12-24 09:17:14

问题


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.



来源:https://stackoverflow.com/questions/15400433/flash-as3-read-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!