Posts in Category "Flash / ActionScript"

How big can your Flash be? See this TechNote…

I just noticed a great TechNote about how big your Flash SWF files can be.

Flash TechNote: How big can a Flash movie be?

The TechNote reviews how big your files can be, how much memory they should use, a bit about math, and so forth. It’s certainly worth a read, particularly if you live on the wild side and ever approach these (logical) limitations.

Sorting and the DataGrid component

Another Tuesday LiveDocs day! The following example continues the theme of DataGrids and sorting.

The following example sorts columns either numerically or alphabetically. By default columns are sorted alphanumerically, so if you had a DataGrid with “1, 213, 11, 7″ it would sort as “1,11,213,7″. By writing a custom sorting function that uses Array.sortOn, you can sort the dataProvider yourself using a numeric or text sort (even sort text as case insensitive).

1. Make sure you have DataGrid in Library
2. Add following ActionScript to frame 1 of the Timeline:

import mx.controls.gridclasses.DataGridColumn;
var my_dp:Array = new Array({name:’Grissom, M.’, avg:0.279}, {name:’Bonds, B.’, avg:0.362}, {name:’Cruz, D.’, avg:0.292}, {name:’Snow, J.’, avg:0.327});
var dg = this.createClassObject(mx.controls.DataGrid, “my_dg”, 999, {dataProvider:my_dp});
dg.setSize(240, 180);
var name_dgc:DataGridColumn = new DataGridColumn(“name”);
name_dgc.headerText = “Name:”;
name_dgc.width = 160;
dg.addColumn(name_dgc);
var avg_dgc:DataGridColumn = new DataGridColumn(“avg”);
avg_dgc.headerText = “Avg:”;
avg_dgc.width = 60;
dg.addColumn(avg_dgc);
//
var myListener:Object = new Object();
myListener.headerRelease = function(evt:Object) {
var sortOrder:String = evt.target.sortDirection;
var sortColumn:String = evt.target.columnNames[evt.columnIndex];
switch (sortColumn) {
case ‘name’ :
sortArray(my_dp, sortColumn, “TEXTNOCASE”, sortOrder);
break;
case ‘avg’ :
sortArray(my_dp, sortColumn, “NUMERIC”, sortOrder);
break;
}
};
my_dg.addEventListener(“headerRelease”, myListener);
//
function sortArray(my_array:Array, sortColumn:String, sortType:String, sortOrder:String) {
var sortOptions:Number = 0;
switch (sortType.toUpperCase()) {
case ‘NUMERIC’ :
sortOptions |= Array.NUMERIC;
break;
case ‘TEXTNOCASE’ :
sortOptions |= Array.CASEINSENSITIVE;
break;
}
if (sortOrder.toUpperCase() == ‘DESC’) {
sortOptions |= Array.DESCENDING;
}
my_array.sortOn(sortColumn, sortOptions);
}

3. Format the code (press the Auto Format button).
4. Test.