![]() | ![]() ![]() ![]() |
![]() | |
![]() | |
![]() |
The DataSet component is a specialized engine that manages a collection of items (transfer objects), each one representing a record of data from an external data source. Items within the collection can be iterated using filters, sorting, ranges, and random access. Using the DataSet component in conjunction with a connector and resolver component provides you with a complete solution for accessing, managing, and updating data between a Flash application and an external data source.
The DataSet component works only with Flash Player 7.
The following are parameters that you can set for the DataSet component:
itemClassName A string that is the name of the transfer object class that is instantiated each time a new item is created within the DataSet component. You must make a fully qualified reference to this class somewhere within your code to make sure that it gets compiled into your application (such as private var myItem:my.package.myItem;
).
The DataSet component uses transfer objects to represent the data that you retrieve from an external data source. If you leave this parameter blank, the data set creates an anonymous transfer object for you. If you give this parameter a value, the data set instantiates your transfer object whenever new data is added.
filtered A Boolean value that defaults to false
. If this parameter is set to true
, a filter is applied to the DataSet component so that it contains only the objects that match the filter criteria.
logChanges A Boolean value that defaults to true
. If this parameter is set to true
, the data set logs all changes to data or method calls.
readOnly A Boolean value that defaults to false
. If this parameter is set to true
, the data set cannot be modified.
The typical workflow for the DataSet component is as follows.
The UI controls are notified as a new record (transfer object) is selected within the DataSet component, and they are updated accordingly. In addition, the Dataset component is notified when data is modified within a UI control, and the change is tracked using the DeltaPacket.
Note: In addition to these steps, you can also bind the DataSet component to a connector and a resolver component to provide a complete solution for accessing, managing, and updating data from an external data source.
For more information on the DataSet component, see DataSet component.
It is important to remember that the DataSet component is a collection of transfer objects. This differs from previous implementations of the component, when it was simply an in-memory cache of data (array of record objects). Transfer objects expose business data from an external data source through public properties or accessor methods. The DataSet component allows enterprise developers to work with sophisticated client-side objects that mirror their server-side counterparts, or in its simplest form, a collection of anonymous objects with public properties representing the fields within a record of data.
There are two data structures that can be used to load data into the DataSet component:
An array of objects can be bound or assigned in code to the DataSet.items
property. A class that implements a DataProvider interface can be bound or assigned in code to the DataSet.dataProvider
property.
The following are examples of loading objects into the DataSet component:
Anonymous objects This example assigns 100 anonymous objects to the DataSet component. Each object represents a record of data.
function loadData() { var recData = new Array(); for( var i:Number=0; i<100; i++ ) { recData[i]= {id:i, name:String("name"+i), price:i*.5}; } myDataSet.items = recData; }
Remoting RecordSet This example assumes that you've made a remoting call that returns a RecordSet. The RecordSet object implements the DataProvider interface.
function getSQLData_Result(result) { myDataset.dataProvider = result; }
Array of objects returned from a web service Using data binding, you can assign an array of objects returned from the web service to the DataSet component's items
property.
Array of objects returned from an XMLConnector component This example assumes that you have read in a schema for an XML file that contains an array of objects. In this scenario, the actual data being returned from the XMLConnector component is an array of XML nodes, which is not supported by the DataSet component. However, data binding (the transport mechanism that is used to copy the data from the XMLConnector component to the DataSet component) implements the DataProvider interface. Therefore, you can assign the array of XML nodes to the DataSet.dataProvider
property, and the data binding feature does the rest.
When you load data into the DataSet component, the date get translated into a collection of transfer objects. In the simplest scenario, the DataSet component creates and loads the data into anonymous objects. Each anonymous object implements the TransferObject interface, which is all that is required for the DataSet component to manage the objects. The DataSet component tracks changes made to the data and any method calls that are made on the objects. If methods are called on an anonymous object, nothing happens, because the methods don't exist. However, the DataSet component tracks them in the DeltaPacket, which guarantees that they will be sent to the external data source, where they can be called if appropriate.
In an enterprise solution you could create a client-side ActionScript transfer object that mirrors a server-side transfer object. This client object could implement additional methods for manipulating the data or applying client-side constraints. Developers can use the itemClassName
parameter of the DataSet component to identify the class name of the client-side transfer object that should be created. In this scenario, the DataSet component generates multiple instances of the specified class and initializes it with the loaded data. When addItem()
is called on the DataSet component, the itemClassName
is used to create an empty instance of the client-side transfer object.
If you take the enterprise solution one step further, you could implement a client-side transfer object that makes use of web services or Flash Remoting. In this scenario, the object would make direct calls on the server in addition to possibly storing the calls in the DeltaPacket.
Note: You can create your own custom transfer object for use by the DataSet component by creating a class that implements the TransferObject interface. For more information on the TransferObject interface, see the Components Dictionary.
Once the data is loaded into the DataSet component, it needs to be accessed. Accessing the data at runtime is simple. Transfer objects expose data through properties that can be referenced in code. The DataSet component has a concept of a cursor that points to the currently selected transfer object. The following code loads a DataSet component with customer information and then displays each customer's name in the trace window:
var recData = [{id:0, firstName:"Frank", lastName:"Jones", age:27, usCitizen:true}, {id:1, firstName:"Susan", lastName:"Meth", age:55, usCitizen:true}, {id:2, firstName:"Pablo", lastName:"Picasso", age:108, usCitizen:false}]; myDataSet.items = recData; myDataSet.first(); while ( myDataSet.hasNext() ) { //access the data through the Dataset attributes trace(myDataSet.firstName + " " + myDataSet.lastName); myDataSet.next(); }
To set up the binding to this data at design time, you create persistent fields for the DataSet component that represent the properties of the transfer object, as in the following example.
var recData = [{id:0, firstName:"Frank", lastName:"Jones", age:27, usCitizen:true}, {id:1, firstName:"Susan", lastName:"Meth", age:55, usCitizen:true}, {id:2, firstName:"Pablo", lastName:"Picasso", age:108, usCitizen:false}]; myDataSet.items = recData;
dataProvider
property of the DataSet component.The data contained within the transfer objects within the data set is now displayed in the data grid.
Creating fields for a DataSet component at design time is the easiest way to expose the properties of a transfer object to data binding. Once the fields are defined, you can visually bind UI controls to the data at design time. Also, there are many additional properties (schema item settings) that can be set at design time for a DataSet field that effect the way data is encoded, formatted, and validated at runtime. See Working with schemas in the Schema tab (Flash Professional only).
The ability to make use of dynamic component properties that are added to the Schema tab at design time is a special feature of the DataSet component. The DataSet component uses the field name of these properties to map them to the properties of the transfer object. The settings that are applied to these properties at design time are then used by the data set at runtime.
If you do not create persistent fields for the DataSet component and you bind it to a WebServiceConnector component or an XMLConnector component that defines a schema, the DataSet component tries to create the correct fields based on the connector component's schema.
Note: Persistent fields that are defined for a DataSet component take precedence over the schema for a connector component.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |