PDA

View Full Version : Read in from TXT file



ImOnCloudNine69
March 24th, 2009, 02:49 PM
I'm storying vars for x and y coordinants for starting and ending positions for movieclips. i wanted to store them in an external file to save space since there are over 100 MC's and i didnt was 4 lines * 100 MC's. the vars are storred in an array.
xstart[num]; ystart[num]; xend[num]; yend[num];. but if there is a more simple way or if using mysql or something works better let me know. I AM OPEN TO SUGJESTIONS


long story short, i have a .TXT file that has numbers in it, one per line. for instance:

1
2
3
4
5

what i need is a flash loop that could put each line into an array. (WITHOUT pre deffining each var name, that would NOT save me time or space in my code because i couldnt use an appropriate loop.)

while (x = 1, not at the end of the file, x++)
{
myArray(x) = next line in the file;
}

IQAndreas
March 24th, 2009, 04:16 PM
Instead of storing it with line breaks each time, perhaps try separating values by commas. Then, you can easily turn it into an array using the split() method.

For example, load the contents of your TXT file into the stringTXT variable.

var stringTXT:String = [TXT file contents];
var locationArray:Array = stringTXT.split(",");


You might also want to consider looking into Flash Cookies (what is the official name again?) for storing the data. Then it can run even if it is being run from online, and you don't have to worry about permission to access the user's computer.