I have decided to start posting some of my code snippets that help me on a regular basis, and now that I have started using Code Collector Pro, I hope to finally keep them all in one place. So in the spirit of sharing the code here is some ActionScript 3 code that loads an external text file ready to be used in a TextField or anything else you need content for.
———– code sample
// Some code to do something with the loaded text
// For example you have a text field instance called
// myTextField, so you could do
// myTextField.text = textLoader.data;
// or for HTML text
// myTextField.htmlText = textLoader.data;
var textLoader:URLLoader = new URLLoader();
var textReq:URLRequest = new URLRequest(“path_to_file”);
———– end code sample
Basically you create an instance of the URLLoader and URLRequest classes and then tell them to load the file and have an EventListener call a method/function and do something with the loaded content. The event Event.COMPLETE only executes after successfully loading the complete file requested.