DataGlue.bindFormatFunction( ) Method | Flash 6 |
binds a data provider to a data consumer using a custom function |
The UI component or other consumer of data to be bound to a data provider.
A RecordSet object or other data provider to be bound to a data consumer.
A custom function that you define that returns an object with the properties label and data. It must accept a single RecordSet object as a parameter.
The DataGlue object is used to bind a data provider to a data consumer. The most common and useful application of this is to bind a RecordSet object to a ListBox, ComboBox, or other UI component that will display the data from the RecordSet. The bindFormatFunction( ) method allows the developer to specify a function to format the appearance of the data in the UI component. If you don't need to format the data, using DataGlue.bindFormatStrings( ) is more straightforward.
The following example code assumes a combo box named allProducts_cb is present on the main timeline:
#include "NetServices.as" #include "DataGlue.as" // Initialize the connection and service objects. if (connected == null) { connected = true; NetServices.setDefaultGatewayUrl("http://localhost/flashservices/gateway"); var my_conn = NetServices.createGatewayConnection( ); var myService = my_conn.getService("com.oreilly.frdg.searchProducts", this); } // The remote getSearchResult( ) method (not shown) returns a recordset. myService.getSearchResult( ); // Display the product names in the combo box. Use the product IDs as the data. // The product names are formatted in uppercase for display. function formatDataForBox (theRecord) { var formatObj = new Object( ); formatObj.label = theRecord.ProductName.toUpperCase( ); formatObj.data = theRecord.ProductID; return formatObj; } // The responder function binds the returned recordset to the combo box. function getSearchResult_Result(result_rs) { DataGlue.bindFormatFunction(allProducts_cb, result_rs, formatDataForBox); }
The formatDataForBox( ) function creates an object with two properties: label and data. This function is called by the bindFormatFunction( ) method for each row in the recordset. The recordset is bound to the combo box, which displays the recordset's capitalized product names in a list and uses the product IDs as the underlying data.
DataGlue.bindFormatStrings( ), the RecordSet class; Chapter 3