Get external txt file content as string variable
Hi everyone,
I apologize if my question is trivial, but I didn't find any solution googling it. I probably don't know even the right search keywords.
My goal is to write one function that:
- read one txt file
- gets txt content as string
So that this string could be manipulated in the remaining part of the code. I found this example:
var myTextLoader: URLLoader = new URLLoader();
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e: Event): void {
trace(e.target.data);
}
myTextLoader.load(new URLRequest("myText.txt"));
It works nicely, but only print txt content in output window. I need content to be stored in a variable and made avaible to the rest of the code.
I tried using a global variable wich assigning target.data to. But when I changed it to this:
var myTextLoader: URLLoader = new URLLoader();
var externalText: String;
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e: Event): void {
externalText = (e.target.data);
}
myTextLoader.load(new URLRequest("myText.txt"));
trace (externalText);
the output is null. I sense I'm missing something fundamental. Could you tell me the correct workflow to get what I'm looking for?
Thanks in advance
