Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to import lines from external text file?

New Here ,
Oct 01, 2015 Oct 01, 2015

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.

TOPICS
ActionScript
291
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Oct 01, 2015 Oct 01, 2015

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]);

}

Translate
Enthusiast ,
Oct 01, 2015 Oct 01, 2015
LATEST

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]);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines