80
Chapter 4: Using Flash Remoting Data in ActionScript
Sorting record sets
To sort the records of a RecordSet object, use the
sortItems
and
sortItemBy()
methods. The
sortItemBy()
method performs an ascending (the default) or descending sort on the records in
the RecordSet object. The
sortItems()
method requires a comparison function as an argument,
and uses that function to sort the records. The
sortItemsBy()
method is implemented natively
in Flash Player 7.x and is substantially faster than the
sortItems()
method.
Sorting a RecordSet object changes the order of the records in the object, but does not otherwise
change the object. Subsequent calls to the
getItemAt()
method return records according to the
new order. After you sort a RecordSet object that was returned from an application, the object no
longer reflects the order of the records on the server-side record set.
The following one-line example sorts the myRecordSet object according to the value of the
DepartmentName field in descending order:
myRecordSet.SortItemsBy("DepartmentName", null, Array.DESCENDING);
The following example sorts a record set prior to displaying it in a ListBox UI component:
function onCustData( re:ResultEvent ):Void {
var rs:RecordSet = RecordSet( re.result );
rs.sortItemsBy(["TotalSales","Name"], null, Array.DESCENDING |
Array.NUMERIC);
DataGlue.bindFormatFunction( cust_ListBox, rs, formatSales);
}
In this example,
cust_ListBox
represents a ListBox UI component in the Flash application. In
the
rs.sortItemsBy()
method, it sorts the records according to the contents of the
TotalSales
column in descending order.
For an example of using the
sortItems()
method, see the RecordSet.sortIems() method in Flash
Remoting ActionScript Dictionary Help.
Note:
For RecordSet objects containing 2,000 or fewer records, the
sortItems()
method generally
takes less than one second to finish on a Pentium 3 computer. The length of time to sort RecordSet
objects increases rapidly as the number of records grows.
Filtering an existing RecordSet object to create a new RecordSet object
The
filter()
method creates a filtered view of a RecordSet object that contains only records that
conform to a set of rules specified by a selection (filter) function that you define. Unlike the
sortItems()
method, the
filter()
method creates a new RecordSet object. The original
RecordSet object and its records remain unchanged.
The selection function that you define takes a record as the first argument, and can take an
optional second argument to determine how to select the records. The function must return a
Boolean
true
or
false
value. Flash Remoting includes in the filtered RecordSet those records for
which the selection function returns
true
. When you call the
filter()
method, you pass it your
selection function and, optionally, the value to use as the selection function’s second argument.
The
RecordSet.filter()
method calls the selection function once for each record in the record
set.
Содержание FLASH REMOTING MX
Страница 1: ...Using Flash Remoting for Flash MX 2004 ActionScript 2 0...
Страница 8: ...8 Contents...
Страница 62: ...62 Chapter 3 Using the RemotingConnector component Flash Professional only...
Страница 142: ...142 Chapter 7 Using Flash Remoting for Java...