Adding records to the RecordSet object
To add items to a RecordSet object, use the
or
methods. The
addItem()
addItemAt()
method adds a record at the end of the record set. The
method inserts a
addItem()
addItemAt()
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
,
, and
removeItemAt()
removeAll()
methods. The
method removes a record at a specific index location,
clear()
removeItemAt()
and the
and
methods remove all records from the RecordSet object. For
removeAll()
clear()
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
method. To replace a
replaceItemAt()
specific field in a record in a RecordSet object, use the
method. For example, the
editField()
following code replaces the contents of the third record in
RecordSet object with
theRecordSet
the contents of the
variable. It then replaces the contents of the third record's
newRecord
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
method is only necessary if you need
addEventListener()
to receive notifications in your own ActionScript code, for example, if you create your own UI
component.
78
Chapter 4: Using Flash Remoting Data in ActionScript
Need help?
Do you have a question about the FLASH REMOTING MX-USING FLASH REMOTING FOR FLASH MX 2004 ACTIONSCRIPT 2.0 and is the answer not in the manual?
Questions and answers