Using Arrays to sort data from a text file AIR

Hey

Currently using a text file to store some basic data. Was thinking of importing that data to a an array and then attempting to sort the data out. Had some guidance to use something along these lines…

[code] function completeHandler(event:Event):void {
var loadedData:URLLoader = URLLoader(event.target);

for (var i:int; i < loadedData.xmlNodeName.length; i++) 
{
test.push(loadedData.xmlNodeName[i]);
MyTextFile_txt.text = loadedData.data;
}

someArray.sort();
}[/code]

Someone suggested the xmlNodeName line of code, but I’m not entirely sure what they mean by that part. Basically getting a little confused and could use some guidance to try and get me back on track.

What does your text data look like?

Nothing too complicated. When I export I use something similar to this.

stream.writeUTFBytes(data1 + data2 + "");

Data1 and data2 just being two different variables.

It doesn’t seem like you’re using XML, so that xmlNodeName business is highly suspect.

Plus, given your example code, it doesn’t look like you have any data separators. If data1 is 15 and data2 is 67, how would you know when reading back “1567” that data1 wasn’t “156” and data2 wasn’t “7”?

That was what I was afraid of.

So basically I need to use the tab character to seperate my data file when I export?

I can then import this data to an array and use…
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7fa4.html

To help sort the records?

I’d just use JSON, if you’re publishing for a version of AIR new enough to support it:

var stream:ByteArray = new ByteArray

var data1:* = 15, data2:* = 67
stream.writeUTFBytes(JSON.stringify({ data1: data1, data2: data2 }))


stream.position = 0
var data = JSON.parse(stream.readUTFBytes(stream.length))
data1 = data.data1
data2 = data.data2

trace(data1, data2)

I’m using CS5 which says AIR 2. Not sure if that is the latest version, but when messing with JSON, it says it is undefined.