I recently resolved an issue where my application crashed while sorting
a DataGrid using a custom sortCompareFunction.
If I was running the application as a Flex app, it crashed my browser.
As an Apollo app, it froze the adl process. This fix may be useful
since I haven't found any other documentation on it. And while the fix
works, I'd appreciate it if anyone could provide insight into the
underlying problem.
Given:
var dg: DataGrid; //is set up and initialized
var dgc: DataGridColumn; // is set up and initialized
function createLabel(object:Object):String; //takes some Vo and returns
a string for use in my datagrid
Problem Code:
dgc.sortCompareFunction = labelSort;
dgc.labelFunction = labelSort;
function labelSort(value1:Object,value2:Object):int
{
// compares value1 and value2 by their labels
// their labels being determined by labelfunction
return createLabel(value1).localeCompare(createLabel(value2));
}
Sorting the datagrid column will ungracefully crash and freeze the whole
application! The following fixes it, but I'm not wholly sure why. My
guess is that it must be a garbage collection issue. This is just one
example of a widespread problem that occurs whenever a calculated value
is directly returned. This type of fix should work in all cases.
function labelSort(value1:Object,value2:Object):int
{
// compares value1 and value2 by their labels
// their labels being determined by labelfunction
var val:int = createLabel(value1).localeCompare(createLabel(value2));
if (val < 0)
return -1;
else if (val > 0)
return 1;
return 0;
}
Nick Matelli | Consultant, Amentra Inc.
Email: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
1775 Wiehle Ave Suite 103, Reston VA 20190
Office: 571.323.0822 x569 Fax: 571.323.0825