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

AS3 Loading text lines from txt file and split

Explorer ,
Dec 01, 2016 Dec 01, 2016

Hello, I have some problems. I have difficulties with external files loading...

I have txt file for example:

SuperMen - Good day

Single - Do your job

Yesterday - Was tomorrow

and etc..

I have script for loading line(this script is mess)...: 3 hours looking for solution trying many things to do but nothing works I get just errors. This script is working now but not how I want.

var answersLoader: URLLoader = new URLLoader();

var answersArray: Array = new Array();

var atlikejasArray: Array = new Array();

var TContent: String

var answer:String;

var i:Number=0;

answersLoader.load(new URLRequest("teams.txt"));

answersLoader.addEventListener(Event.COMPLETE, answersLoaded);

function answersLoaded(event: Event): void {

    answersLoader.removeEventListener(Event.COMPLETE, answersLoaded);

    TContent = event.target.data;

    answersArray = TContent.split("\n");

    answer = answersArray;

    atlikejasArray = answer.split("\-");

    textfield1.text = atlikejasArray[0];

    textfield2.text = atlikejasArray[1];

}

But problem is that It works one time.

I have other script:

function addanswer(){

     stage.addChild(newlines);

     newlines. textfield1.text = atlikejasArray[0];

     newlines. textfield2.text = atlikejasArray[1];

     newlines.play();

}

In the result I want to see ONE LINE from txt file IN two different textfields.

EVERYTIME I ADD THE CHILD I WANT TO SEE DIFFERENT LINE FROM TXT FILE IN TWO DIFFERENT TEXFIELDS.

Line in txt file:

SuperMen - Good day

I want to get:

newlines.textfield1.text = SuperMen

newlines.textfield2.text = Good day

call function i++;

call function addanswer();

Line:

Single - Do your job

newlines.textfield1.text = Single

newlines.textfield2.text = Do your job

How I can to fix this script for good working script. I just want to call function and get result.

Maby someone can help me. Im just lost..

TOPICS
ActionScript
2.5K
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

Community Expert , Dec 01, 2016 Dec 01, 2016

use:

I have txt file for example:

SuperMen - Good day

Single - Do your job

Yesterday - Was tomorrow

//

var answersLoader: URLLoader = new URLLoader();

var answersArray: Array = new Array();

var atlikejasArray: Array = new Array();

var i:int = 0;

answersLoader.load(new URLRequest("teams.txt"));

answersLoader.addEventListener(Event.COMPLETE, answersLoaded);

function answersLoaded(event: Event): void {

answersLoader.removeEventListener(Event.COMPLETE, answersLoaded);

answersArray = event.target.data.split("\n"

...
Translate
Community Expert ,
Dec 01, 2016 Dec 01, 2016

use:

I have txt file for example:

SuperMen - Good day

Single - Do your job

Yesterday - Was tomorrow

//

var answersLoader: URLLoader = new URLLoader();

var answersArray: Array = new Array();

var atlikejasArray: Array = new Array();

var i:int = 0;

answersLoader.load(new URLRequest("teams.txt"));

answersLoader.addEventListener(Event.COMPLETE, answersLoaded);

function answersLoaded(event: Event): void {

answersLoader.removeEventListener(Event.COMPLETE, answersLoaded);

answersArray = event.target.data.split("\n");

tfF();

}

function tfF():void{

atlikejasArray = answersArray.split(" - ");

textfield1.text = atlikejasArray[0];

textfield2.text = atlikejasArray[1];

i++;

if(i==answersArray.length){

// done

}

}

// call tfF() for the next line

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
Explorer ,
Dec 01, 2016 Dec 01, 2016

In txt file i have Lithuanian language letters like ĄČĘĖĮŠŲŪŽ

But when I uploading to text screen I have different letters ÀÈÆËÁÐØÛÞ

All fonts already embeded. When I write in simple text I see letters but when I uploading from somewhere to textfields they are different.

Almost a YEAR I`m looking for some solution but nothing. With AS2 everything is fine but with AS3 is wrong.

And I don`t understand why.

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
Community Expert ,
Dec 02, 2016 Dec 02, 2016
LATEST

your text file should be saved with unicode, not ansi to preserve the encoding.

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
Explorer ,
Dec 01, 2016 Dec 01, 2016

Hm.. I get All in one line

SuperMen - Good day

Not in different textfields

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
Explorer ,
Dec 01, 2016 Dec 01, 2016

Sorry its my foult Thanks a lot:)

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