dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [AS3]How do i sort a object array?

  1. #1
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766

    [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?

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    http://livedocs.adobe.com/flash/9.0/...fV3/index.html

    look at - Array.sortOn () method and the Date class

  3. #3
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    sorry to sound dumb, but i dont know how to do any of the two i asked, can you please give an answer here?

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    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 0records.lengthi++) {
        
    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 0records.lengthi++) {
        
    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 0records.lengthi++) {
        
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center