PDA

View Full Version : sorting array with multiple fields



Flashmatazz
September 25th, 2004, 04:25 PM
Heya,

a quick question: I have an array that gets filled with values from a database and I want to sort things in Flash using the sortOn() function. I'm trying to create an array with a number of fields, like this example from the Help-files:



var my_array:Array = new Array();
my_array.push({password: "Bob", age:29});
my_array.push({password: "abcd", age:3});
my_array.push({password: "barb", age:35});
my_array.push({password: "catchy", age:4});


However, I need a bit more fields and if I put all of these in one line, it gets kinda lengthy.
I tried something like


var my_array:Array = new Array();
for (i=0; i<10; i++) {
my_array.push ( {prop1: "value_1_"+i} );
my_array.push ( {prop2: "value_2_"+i} );
}

but this apparently doesn't work. Is there another way of doing this?

Cheers.

Flashmatazz
September 25th, 2004, 04:36 PM
whoops, I was a bit to quick to post my question. already got it sorted out so it doesn't get too messy. I just assign within the loop each nodename/attribute from the XML object containing my data to a variable first and at the end push all these values into the fields of the array. so still in one line, but not so messy as I feared :D