Skip to main content
paparasi44674042
Participant
August 16, 2019
Question

trace from external file

  • August 16, 2019
  • 1 reply
  • 495 views

Hi everybody,

I am working on a project and I am using "trace()" to check the values that I load from an external file, in my case a csv file.

my code which fails is  the following:

trace(n1.text =  loadedData[0][0]);

trace(n2.text =  loadedData[1][0]);

trace(n3.text =  loadedData[2][0]);

trace(n4.text =  loadedData[3][0]);

trace(n5.text =  loadedData[4][0]);

trace(n6.text =  loadedData[5][0]);

trace(n7.text =  loadedData[6][0]);

trace(n8.text =  loadedData[7][0]);

if

(n1.text ==  loadedData[0][0])

{

(n1.text =  loadedData[0][0]);

(s1.text =  loadedData[0][1]);

(t1.text =  loadedData[0][2]);

(c1.text =  loadedData[0][3]);

}

else if

(n1.text == "")

{

gotoAndStop(6)

}

The problem is that I need to prepare a template with 8 text fields but the csv file that I load sometimes has 6 7 or 8 lines.

So when I trace 8 lines from my csv and there are less than 8 it doesn't work.

any suggestions?

This topic has been closed for replies.

1 reply

Legend
August 17, 2019

Why in god's name are you performing assignment within your trace statements? Trace statements should never, ever contain essential code.

And why aren't you just using a loop instead of hard-coding eight trace statements?

paparasi44674042
Participant
August 18, 2019

Hi ClayUUID

I know it sounds stupid and probably  it is, as well as it is wrong, but it didn't work when I just traced the loadingData alone.

as it concerns the loop you suggested I don't know how to use it so I write everything by hand. I will give it a try though.

Still if you have any suggestions concerning my real problem I will be thankfull.

kglad
Community Expert
Community Expert
August 18, 2019

it's not clear which you're using both loadedData[0] and loadedData[0], but this is one way to use a loop for one of those situations:

var i:int=0;

while(loadedData[0].length>0){

this['n'+(i+1)].text = loadedData[0];

trace(loadedData[0];

i++;

// you might want a break.  i can't tell

}