Copy link to clipboard
Copied
Hello,
I have been struggling with external text files for pretty long time now. I have lots of text and that is why I think I should take it from external file for easier editing and of course cleaner code.
For example:
week.txt
Monday is a nice day.
Tuesday is too.
Wednesday is also.
Thursday is not.
Friday is maybe.
Saturday is maybe not.
Sunday is definitely.
I should have a code that will somehow take these lines apart from each other and show them one by one (first the first line, second the second, third time the third line...) whenever I call for a function. I know I can probably use \n to determinate where line ends but I am not sure how to do it. Handling text is not something I do that often.
I am also not sure if this is a good way of handling this situation but I would still like to know how to do this.
I am not asking for straight code (although I of course would also appreciate it) but some tips that will help me get closer to how to do this.
1 Correct answer
The simplest method is to use URLLoader. Something like this should get you started:
var l:URLLoader = new URLLoader();
l.addEventListener(Event.COMPLETE, loaded);
l.load(new URLRequest("week.txt"));
function loaded(e:Event):void
{
var a:Array = String(l.data).split("\n");
trace(a.length);
trace(a[0]);
}
Copy link to clipboard
Copied
The simplest method is to use URLLoader. Something like this should get you started:
var l:URLLoader = new URLLoader();
l.addEventListener(Event.COMPLETE, loaded);
l.load(new URLRequest("week.txt"));
function loaded(e:Event):void
{
var a:Array = String(l.data).split("\n");
trace(a.length);
trace(a[0]);
}

