-
Senior Member
[AS3]How do i sort a object array?
I have array of objects, and the objects have their properties like subject, text, date, etc. Now i want to sort the array based on the date property of the objects, any ideas on how to do this?
Also the date is being taken from the "time()" function in php and is formatted in php in the form dd/mm/yyyy , before getting into flash! Is there any easy way to format the date in flash like php?
-
FK'n_dog
-
Senior Member
sorry to sound dumb, but i dont know how to do any of the two i asked, can you please give an answer here?
-
FK'n_dog
PHP Code:
var records:Array = new Array();
records.push({name:"john", city:"omaha", zip:68144});
records.push({name:"john", city:"kansas city", zip:72345});
records.push({name:"bob", city:"omaha", zip:94010});
for(var i:uint = 0; i < records.length; i++) {
trace(records[i].name + ", " + records[i].city);
}
// Results:
// john, omaha
// john, kansas city
// bob, omaha
trace("records.sortOn('name', 'city');");
records.sortOn(["name", "city"]);
for(var i:uint = 0; i < records.length; i++) {
trace(records[i].name + ", " + records[i].city);
}
// Results:
// bob, omaha
// john, kansas city
// john, omaha
trace("records.sortOn('city', 'name');");
records.sortOn(["city", "name"]);
for(var i:uint = 0; i < records.length; i++) {
trace(records[i].name + ", " + records[i].city);
}
// Results:
// john, kansas city
// bob, omaha
// john, omaha
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|