# Array.sortOn with objects of a custom class?

**URL:** <https://forum.kirupa.com/t/array-sorton-with-objects-of-a-custom-class/233872>\
**Category:** flash\
**Created:** [July 27, 2007, 5:02pm UTC](https://forum.kirupa.com/t/array-sorton-with-objects-of-a-custom-class/233872 "2007-07-27T17:02:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveistheword](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@daveistheword](https://forum.kirupa.com/u/daveistheword)\
**Post date:** [July 27, 2007, 5:02pm UTC](https://forum.kirupa.com/t/array-sorton-with-objects-of-a-custom-class/233872/1 "2007-07-27T17:02:20Z")

</div>

I have a problem - I’m trying to do Array.sortOn on an array of custom-class objects. It’s not working, though nothing in the documentation suggests that this is a problem. Below is the code. I’m confident the MetricRecord constructor is working fine because everything else works, and the traces below are correct, except they don’t sort.

Does anyone have any insight into this? I’d be very grateful.

Dave

// This array sorts  
metricRecords = new Array();  
metricRecords.push({mediaVehicle:“cca”, temp:“asxcvbxcber”});  
metricRecords.push({mediaVehicle:“aaa”, temp:“asdfertr”});  
metricRecords.push({mediaVehicle:“ttt”, temp:“asghjtryder”});  
metricRecords.push({mediaVehicle:“ddd”, temp:“assdfer”});

// this array doesn’t sort  
metricRecords = new Array();  
metricRecords.push(new MetricRecord(15, new MetricType(), “nnnn”, “asdf”, 15, 25, 28, “notes temp”));  
metricRecords.push(new MetricRecord(12, new MetricType(), “ddd”, “asdf”, 15, 25, 28, “notes temp”));  
metricRecords.push(new MetricRecord(13, new MetricType(), “bbb”, “asdf”, 15, 25, 28, “notes temp”));  
metricRecords.push(new MetricRecord(17, new MetricType(), “aaaa”, “asdf”, 15, 25, 28, “notes temp”));

for (i=0; i\<metricRecords.length; i++){  
trace("…"+metricRecords\*.mediaVehicle);  
}

metricRecords.sortOn(“mediaVehicle”);  
trace("/////////////////////");

for (i=0; i\<metricRecords.length; i++){  
trace("…"+metricRecords\*.mediaVehicle);  
}
