84
Chapter 4: Using Flash Remoting Data in ActionScript
By default, each label value is a comma-delimited string that consists of the contents of one
record’s fields; the data values are not set. However, you can use a RecordSet object directly in the
dataProvider
property to provide both the list and data values if the record set has two columns
and the column names are label and data. For example, the following SQL code produces a record
set that, when passed to the preceding
getProductList_Result()
function, populates the
catalogListBox object with both label and data values:
SELECT COST_CENTER AS DATA, DESCRIPTION AS LABEL
FROM EMPDB_DEPARTMENT
WHERE STATUS='Active'
Using DataGlue methods
The DataGlue class methods,
bindFormatStrings
and
bindFormatFunction
, let you specify
how a RecordSet object supplies the contents of both the data and value fields of a data consumer.
The DataGlue class methods provide substantial flexibility in formatting the contents of the labels
and data, as follows:
•
The
bindFormatStrings()
method lets you independently specify strings that contain any
number of record set fields and other data as the sources of the label and data contents.
•
The
bindFormatFunction()
method lets you specify any function to provide the data to the
data consumer. The function must take a record as an argument and returns an object that
consists of two entries: a label field and a data field. The function has full flexibility in using
the record contents to generate and format the label and data values.
The DataGlue class methods do not make a copy of the DataProvider object. However, the data is
fetched from the data provider as needed by the component.
Using the bindFormatStrings method
The
bindFormatStrings()
method lets you freely format record fields and string data. For
example, the following method uses values from two fields to generate the labels and from three
fields to generate the data values:
DataGlue.bindFormatStrings (myComboBox, myRecordSet, "#parkname#
(#parktype#)", "#city#, #state# #zipcode#");
In this example, myComboBox represents a ComboBox component in the Flash application, and
myRecordSet represents the RecordSet object. The parkname, parktype, city, state, and zip code
variables represent record field names. The Flash application displays the parkname and parktype
variables in the ComboBox. The city, state, and zipcode variables are returned when the user
selects the record and ActionScript code uses a
getValue
,
getSelectedItem
, or similar, method.
Using the bindFormatFunction() method
The
bindFormatFunction()
method lets you call a function to format the data for your data
consumer. Your function must take a record as its argument and return an object with the
following format:
{label: labelValue, data: dataValue};