RecordSet.getItemID( ) Method | Flash 6 |
retrieves the internal ID number of a row |
An integer between 0 and the length of the RecordSet object minus one.
The internal ID number that Flash assigns when the record is added to the recordset.
The getItemID( ) method returns an internal ID and is useful for determining the initial state of the RecordSet object (or the order in which records were added). If the order of the records in the recordset changes in some way, it can be restored or compared by using the original identifier that was given to each row when the recordset was created. Unlike the index of a record, which can change, the internal ID never changes and is destroyed if the row is deleted. The identifier of a deleted row is not reused again.
The following code retrieves the original first row from the recordset, even after the sort changes the order of the rows:
#include "RecordSet.as" var myRecordset_rs = new RecordSet(["First","Last","Email"]); myRecordset_rs.addItem({First:"Tom", Last:"Muck", Email:"tom@tom-muck.com"}); myRecordset_rs.addItem({First:"Jack", Last:"Splat", Email:"jack@tom-muck.com"}); myRecordset_rs.addItem({First:"Biff", Last:"Bop", Email:"biff@tom-muck.com"}); // "Tom Muck" is the first item before the sort. After the sort, it is second. myRecordset_rs.sortItemsBy("Last"); // Loop through the records looking for the one whose original ID is 0 for (var i; i < myRecordset_rs.getLength( ); i++) { if (myRecordset_rs.getItemID(i) == 0) { trace(myRecordset_rs.getItemID(i)); break; } }
After the recordset is sorted, the first record is "Biff Bop", but its item ID is still 2. The second record in the sorted recordset is "Tom Muck", but its item ID is 0, telling us that it was the original first record. The trace( ) statement displays Tom's record in the Output window.
RecordSet.addItemAt( ), RecordSet.sortItemsBy( ); Chapter 3 and Chapter 4