DataProvider API

The DataProvider API is a set of methods and properties that a data source needs so that a list-based class can communicate with it. Arrays, recordsets, and data sets implement this API. You can create a DataProvider-compliant class by implementing all the methods and properties described in this section. A list-based component could then use that class as a data provider.

NOTE

 

The DataProvider API is supported only if you are working in a document that specifies ActionScript 2.0 in its Publish Settings.

DataProvider class

ActionScript Class Name mx.controls.listclasses.DataProvider

The methods of the DataProvider class let you query and modify the data in any component that displays data (also called a view). The DataProvider API also broadcasts change events when the data changes. Multiple views can use the same data provider and receive the change events.

A data provider is a linear collection (like an array) of items. Each item is an object composed of many fields of data. You can access these items by index (as you can with an array), using DataProvider.getItemAt().

Data providers are most commonly used with arrays. Data-aware components apply all the methods of the DataProvider API to Array.prototype when an Array object is in the same frame or screen as a data-aware component. This lets you use any existing array as the data for views that have a dataProvider property.

Because of the DataProvider API, the components that provide views for data (DataGrid, List, Tree, and so on) can also display Flash Remoting RecordSet objects and data from the DataSet component. The DataProvider API is the language with which data-aware components communicate with their data providers.

In the Adobe Flash documentation, "DataProvider" is the name of the class, dataProvider is a property of each component that acts as a view for data, and "data provider" is the generic term for a data source.

Method summary for the DataProvider API

The following table lists the methods of the DataProvider API.

Method

Description

DataProvider.addItem()

Adds an item at the end of the data provider.

DataProvider.addItemAt()

Adds an item to the data provider at the specified position.

DataProvider.editField()

Changes one field of the data provider.

DataProvider.getEditingData()

Gets the data for editing from a data provider.

DataProvider.getItemAt()

Gets a reference to the item at a specified position.

DataProvider.getItemID()

Returns the unique ID of the item.

DataProvider.removeAll()

Removes all items from a data provider.

DataProvider.removeItemAt()

Removes an item from a data provider at a specified position.

DataProvider.replaceItemAt()

Replaces the item at a specified position with another item.

DataProvider.sortItems()

Sorts the items in the data provider according to a compare function or sort options.

DataProvider.sortItemsBy()

Sorts the items in the data provider alphabetically or numerically, in the specified order, using the specified field name.

Property summary for the DataProvider API

The following table lists the properties of the DataProvider API.

Property

Description

DataProvider.length

The number of items in a data provider.

Event summary for the DataProvider API

The following table lists the events of the DataProvider API.

Event

Description

DataProvider.modelChanged

Broadcast when the data provider is changed.


Flash CS3