I was looking at writing a re-usable sortCompareFunction for use with DataGrids but I think I am missing something obvious. A sort compare function has a signature that looks like:
function mySort(obj1: Object, obj2: Object): int
Now assume that the Data for the grid contains Objects that have fields "A", "B" and "C".
When the mySort() function is called to sort data, it doesn't seem that I know which column/field in the data the sort should be applied to. It would appear that I would have to write three sort functions, one for "A", one for "B" and one for "C" and define each of these for the sortCompareFunction for the corresponding column. But in my solution I can't do this as I have a dynamic/variable number of columns and don't know ahead of time the field name in the object that I need to sort upon.
I assume you could always take this approach
public function doSortForField(field:String):Function
return function(obj1:Object, obj2:Object):int
And extend the method (or build a class) to support an array of fields rather than a single field.
Bonus points for also supporting varying types.
You rock. I am new to AS3 and couldn't see how to use closures with such a solution but your example has opened my eyes to a wealth of new techniques. Thank you sir!!