Could u upload an array not a single variable from a file

8 posts

Flag Post

Could u?

 
Flag Post

If you can read something from a file, you can also fill an array with what you’ve read.

What exactly is causing you trouble?

 
Flag Post

If you mean when you’re loading data from a text file or somesuch: load it as a string and explode it into an array.

 
Flag Post

Yeah you can do what Kalinium suggested, that’s a good method. Or, you could also try making an .xml file and then parsing the XML data into an array.

 
Flag Post

Having said that, I can’t find the AS explode function :S

 
Flag Post

What the heck is an array anyway?

 
Flag Post

It’s like a list.

MyArray0 is the first item in the list, which acts just like a variable, so you could do

MyArray = new Array()

MyArray0 = 1
MyArray1 = 2
MyArray2 = “Hello”
MyArray3 = MyArray0 + MyArray1

trace(MyArray2 + String(MyArray3) //Traces “Hello3”

 
Flag Post

Arrays are a pretty basic data type… there should be tons of info about them if you Google it. The thing that you’re looking for is actually a method of the String class,

String.split()

Say you have a bunch of data in your file. It could look like this:
data 1_data 2_data 3_fred_taco_1234_abcd

Whatever the data is, the important part is to separate each piece of the data with an underscore. Then, when you load that data into a string inside Flash, you can use the split function to create an array. Here’s what that code would look like:
var myArray:Array = myString.split(“_”);

Ok, now you have split all the little substrings (pieces of data) into an array. Now you can access the data like Kalinium was saying above. For example:
trace(myArray
3);
will trace the value
fred

to the output window.

Hope that helps :)