RecordSet.addView( ) Method | Flash 6 |
monitors RecordSet activity by watching certain events |
myRecordSet .addView( object )
Event | Information object returned | Occurs when |
---|---|---|
addItem( ) and addItemAt( ) methods | {event:"addRows", firstRow: n , lastRow: nn } | Row numbers between n and nn are added |
onResult( ) method of responder object | {event:"allRows"} | The recordset is fully populated from the server |
removeAll( ) , removeItemAt( ) | {event:"deleteRows", firstRow: n , lastRow: nn } | Row numbers between n and nn are deleted |
onResult( ) method of responder object | {event:"fetchrows", firstRow: n , lastRow: nn } | Row numbers between n and nn are requested from the server, but have not yet arrived |
sort ( ) and sortItemsBy( ) methods | {event: "sort"} | A recordset is sorted |
Any change in the RecordSet | {event:"updateAll"} | A recordset changes in any way |
replaceItemAt( ) , setField( ) | {event:"updateRows", firstRow: n , lastRow: nn } | Row numbers between n and nn change in any way |
First, create an ActionScript object that defines a modelChanged( ) method, like this:
var myObject = new Object( ); myObject.prototype.modelChanged = function (myInformationObject) { trace(myInformationObject.event); };
Then call addView( ) , passing myObject as a parameter:
myRecordset_rs.addView(myObject);
This causes myObject 's modelChanged( ) method to be invoked whenever the contents of myRecordset_rs change. When an event triggers the modelChanged( ) method, it receives an information object ( myInformationObject ) as a parameter. This information object contains an event property, indicating the type of change that occurred to the recordset, as shown in Table 15-3. Some objects passed to modelChanged( ) also contain firstRow and lastRow properties indicating the range or record numbers affected.
Here is a fleshed-out example that displays a message in the Output window whenever the recordset is sorted:
#include "RecordSet.as" var myRecordset_rs = new RecordSet(["First","Last","Email"]); // Create the generic object var myObject = new Object( ); // Add a modelChanged( ) event handler the object myObject.modelChanged = function (myInformationObject) { if (myInformationObject.event == "sort") { trace("RecordSet was sorted"); } }; // Call addView( ) to set up the callback function ( myObject.modelChanged ) myRecordset_rs.addView(myObject); myRecordset_rs.addItem({First:"Tom",Last:"Muck",Email:"tom@tom-muck.com"}); myRecordset_rs.addItem({First:"Jack",Last:"Splat",Email:"jack@tom-muck.com"}); // Sort the recordset, triggering the modelChanged( ) method myRecordset_rs.sortItemsBy("First");
At this point, the Output window should display "RecordSet was sorted."
Chapter 4 ( especially Example 4-3)