User Guide

Table Of Contents
78 Chapter 4: Using Flash Remoting Data in ActionScript
Adding records to the RecordSet object
To add items to a RecordSet object, use the addItem() or addItemAt() methods. The
addItem() method adds a record at the end of the record set. The addItemAt() method inserts a
record at the specific index location; the indexes of all the other records in the RecordSet object
are automatically incremented by one. For example, the following adds a single record at the
beginning of the myRecordSet object:
var newRecord = {DepartmentID: "BA1EA7FF0-7D79-32D3-A9280050042189548",
DepartmentName: "Technical Publications"};
myRecordSet.addItemAt(0, newRecord);
Removing records from the RecordSet object
To remove records from a RecordSet object, use the removeItemAt(), removeAll(), and
clear() methods. The removeItemAt() method removes a record at a specific index location,
and the
removeAll() and clear() methods remove all records from the RecordSet object. For
example, the following line removes the record at the first index location (0). The indexes of all
the other records in the RecordSet object are automatically decremented by one:
theRecordSet.removeItemAt(0);
Replacing and renaming records in the RecordSet object
To replace a record in a RecordSet object, you use the replaceItemAt() method. To replace a
specific field in a record in a RecordSet object, use the
editField() method. For example, the
following code replaces the contents of the third record in
theRecordSet RecordSet object with
the contents of the
newRecord variable. It then replaces the contents of the third records
DepartmentName field:
var newRecord = {DepartmentID: "BA1EA720-7D79-11D3-A9280050042189548",
DepartmentName: "Complaints"};
theRecordSet.replaceItemAt(2, newRecord);
theRecordSet.editField(2,"DepartmentName","Compliments");
Using notifications with RecordSet objects
You can notify any ActionScript object of changes in a RecordSet object’s internal state. For
example, if you associate a RecordSet object with a ListBox component, and the record set gets
sorted into a different order, Flash can notify the ListBox component that the record order
changed, so the ListBox component can redraw itself according to the new order.
Similarly, a RecordSet object can notify its associated ListBox component when all records arrive
from the server. Then, if required, the ListBox can redraw itself to update its display.
Note: Flash UI components such as ListBox incorporate notifications as a standard part of their use
of the RecordSet ActionScript class. The
addEventListener() method is only necessary if you need
to receive notifications in your own ActionScript code, for example, if you create your own UI
component.