Packagefl.data
Classpublic class DataProvider
InheritanceDataProvider Inheritance flash.events.EventDispatcher

The DataProvider class provides methods and properties that allow you to query and modify the data in any list-based component--for example, in a List, DataGrid, TileList, or ComboBox component.

A data provider is a linear collection of items that serve as a data source--for example, an array. Each item in a data provider is an object or XML object that contains one or more fields of data. You can access the items that are contained in a data provider by index, by using the DataProvider.getItemAt() method.



Public Properties
 PropertyDefined by
  length : uint
[read-only] The number of items that the data provider contains.
DataProvider
Public Methods
 MethodDefined by
  
DataProvider(value:Object = null)
Creates a new DataProvider object using a list, XML instance or an array of data objects as the data source.
DataProvider
  
addItem(item:Object):void
Appends an item to the end of the data provider.
DataProvider
  
addItemAt(item:Object, index:uint):void
Adds a new item to the data provider at the specified index.
DataProvider
  
addItems(items:Object):void
Appends multiple items to the end of the DataProvider and dispatches a DataChangeType.ADD event.
DataProvider
  
addItemsAt(items:Object, index:uint):void
Adds several items to the data provider at the specified index and dispatches a DataChangeType.ADD event.
DataProvider
  
Creates a copy of the current DataProvider object.
DataProvider
  
concat(items:Object):void
Concatenates the specified items to the end of the current data provider.
DataProvider
  
getItemAt(index:uint):Object
Returns the item at the specified index.
DataProvider
  
getItemIndex(item:Object):int
Returns the index of the specified item.
DataProvider
  
invalidate():void
Invalidates all the data items that the DataProvider contains and dispatches a DataChangeEvent.INVALIDATE_ALL event.
DataProvider
  
invalidateItem(item:Object):void
Invalidates the specified item.
DataProvider
  
invalidateItemAt(index:int):void
Invalidates the item at the specified index.
DataProvider
  
merge(newData:Object):void
Appends the specified data into the data that the data provider contains and removes any duplicate items.
DataProvider
  
removeAll():void
Removes all items from the data provider and dispatches a DataChangeType.REMOVE_ALL event.
DataProvider
  
removeItem(item:Object):Object
Removes the specified item from the data provider and dispatches a DataChangeType.REMOVE event.
DataProvider
  
removeItemAt(index:uint):Object
Removes the item at the specified index and dispatches a DataChangeType.REMOVE event.
DataProvider
  
replaceItem(newItem:Object, oldItem:Object):Object
Replaces an existing item with a new item and dispatches a DataChangeType.REPLACE event.
DataProvider
  
replaceItemAt(newItem:Object, index:uint):Object
Replaces the item at the specified index and dispatches a DataChangeType.REPLACE event.
DataProvider
  
sort(... sortArgs):*
Sorts the items that the data provider contains and dispatches a DataChangeType.SORT event.
DataProvider
  
sortOn(fieldName:Object, options:Object = null):*
Sorts the items that the data provider contains by the specified field and dispatches a DataChangeType.SORT event.
DataProvider
  
toArray():Array
Creates an Array object representation of the data that the data provider contains.
DataProvider
  
toString():String
Creates a string representation of the data that the data provider contains.
DataProvider
Events
 EventSummaryDefined by
   Dispatched after the data is changed.DataProvider
   Dispatched before the data is changed.DataProvider
Property detail
lengthproperty
length:uint  [read-only]

The number of items that the data provider contains.

Implementation
    public function get length():uint
Constructor detail
DataProvider()constructor
public function DataProvider(value:Object = null)

Creates a new DataProvider object using a list, XML instance or an array of data objects as the data source.

Parameters
value:Object (default = null) — The data that is used to create the DataProvider.
Method detail
addItem()method
public function addItem(item:Object):void

Appends an item to the end of the data provider.

Parameters
item:Object — The item to be appended to the end of the current data provider.

See also

addItemAt()method 
public function addItemAt(item:Object, index:uint):void

Adds a new item to the data provider at the specified index. If the index that is specified exceeds the length of the data provider, the index is ignored.

Parameters
item:Object — An object that contains the data for the item to be added.
 
index:uint — The index at which the item is to be added.

Throws
— The specified index is less than 0 or greater than or equal to the length of the data provider.

See also

addItems()method 
public function addItems(items:Object):void

Appends multiple items to the end of the DataProvider and dispatches a DataChangeType.ADD event. The items are added in the order in which they are specified.

Parameters
items:Object — The items to be appended to the data provider.

See also

addItemsAt()method 
public function addItemsAt(items:Object, index:uint):void

Adds several items to the data provider at the specified index and dispatches a DataChangeType.ADD event.

Parameters
items:Object — The items to be added to the data provider.
 
index:uint — The index at which the items are to be inserted.

Throws
— The specified index is less than 0 or greater than or equal to the length of the data provider.

See also

clone()method 
public function clone():DataProvider

Creates a copy of the current DataProvider object.

Returns
DataProvider — A new instance of this DataProvider object.
concat()method 
public function concat(items:Object):void

Concatenates the specified items to the end of the current data provider. This method dispatches a DataChangeType.ADD event.

Parameters
items:Object — The items to be added to the data provider.

See also

getItemAt()method 
public function getItemAt(index:uint):Object

Returns the item at the specified index.

Parameters
index:uint — Location of the item to be returned.

Returns
Object — The item at the specified index.

Throws
— The specified index is less than 0 or greater than or equal to the length of the data provider.

See also

getItemIndex()method 
public function getItemIndex(item:Object):int

Returns the index of the specified item.

Parameters
item:Object — The item to be located.

Returns
int — The index of the specified item, or -1 if the specified item is not found.

See also

invalidate()method 
public function invalidate():void

Invalidates all the data items that the DataProvider contains and dispatches a DataChangeEvent.INVALIDATE_ALL event. Items are invalidated after they are changed; the DataProvider automatically redraws the invalidated items.

See also

invalidateItem()method 
public function invalidateItem(item:Object):void

Invalidates the specified item. An item is invalidated after it is changed; the DataProvider automatically redraws the invalidated item.

Parameters
item:Object — Item to be invalidated.

See also

invalidateItemAt()method 
public function invalidateItemAt(index:int):void

Invalidates the item at the specified index. An item is invalidated after it is changed; the DataProvider automatically redraws the invalidated item.

Parameters
index:int — Index of the item to be invalidated.

Throws
— The specified index is less than 0 or greater than or equal to the length of the data provider.

See also

merge()method 
public function merge(newData:Object):void

Appends the specified data into the data that the data provider contains and removes any duplicate items. This method dispatches a DataChangeType.ADD event.

Parameters
newData:Object — Data to be merged into the data provider.

See also

removeAll()method 
public function removeAll():void

Removes all items from the data provider and dispatches a DataChangeType.REMOVE_ALL event.

See also

removeItem()method 
public function removeItem(item:Object):Object

Removes the specified item from the data provider and dispatches a DataChangeType.REMOVE event.

Parameters
item:Object — Item to be removed.

Returns
Object — The item that was removed.

See also

removeItemAt()method 
public function removeItemAt(index:uint):Object

Removes the item at the specified index and dispatches a DataChangeType.REMOVE event.

Parameters
index:uint — Index of the item to be removed.

Returns
Object — The item that was removed.

Throws
— The specified index is less than 0 or greater than or equal to the length of the data provider.

See also

replaceItem()method 
public function replaceItem(newItem:Object, oldItem:Object):Object

Replaces an existing item with a new item and dispatches a DataChangeType.REPLACE event.

Parameters
newItem:Object — The item to be replaced.
 
oldItem:Object — The replacement item.

Returns
Object — The item that was replaced.

Throws
— The item could not be found in the data provider.

See also

replaceItemAt()method 
public function replaceItemAt(newItem:Object, index:uint):Object

Replaces the item at the specified index and dispatches a DataChangeType.REPLACE event.

Parameters
newItem:Object — The replacement item.
 
index:uint — The index of the item to be replaced.

Returns
Object — The item that was replaced.

Throws
— The specified index is less than 0 or greater than or equal to the length of the data provider.

See also

sort()method 
public function sort(... sortArgs):*

Sorts the items that the data provider contains and dispatches a DataChangeType.SORT event.

Parameters
... sortArgs — The arguments to use for sorting.

Returns
* — The return value depends on whether the method receives any arguments. See the Array.sort() method for more information. This method returns 0 when the sortOption property is set to Array.UNIQUESORT.

See also

sortOn()
Array.sort()
sortOn()method 
public function sortOn(fieldName:Object, options:Object = null):*

Sorts the items that the data provider contains by the specified field and dispatches a DataChangeType.SORT event. The specified field can be a string, or an array of string values that designate multiple fields to sort on in order of precedence.

Parameters
fieldName:Object — The item field by which to sort. This value can be a string or an array of string values.
 
options:Object (default = null) — Options for sorting.

Returns
* — The return value depends on whether the method receives any arguments. For more information, see the Array.sortOn() method. If the sortOption property is set to Array.UNIQUESORT, this method returns 0.

See also

sort()
Array.sortOn()
toArray()method 
public function toArray():Array

Creates an Array object representation of the data that the data provider contains.

Returns
Array — An Array object representation of the data that the data provider contains.
toString()method 
public override function toString():String

Creates a string representation of the data that the data provider contains.

Returns
String — A string representation of the data that the data provider contains.
Event detail
dataChangeevent 
Event object type: fl.events.DataChangeEvent
DataChangeEvent.type property = fl.events.DataChangeEvent.DATA_CHANGE

Dispatched after the data is changed.

Defines the value of the type property of a dataChange event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
changeTypeIdentifies the type of change that was made.
currentTargetThe object that is actively processing the event object with an event listener.
endIndexIdentifies the index of the last changed item.
itemsAn array that lists the items that were changed.
startIndexIdentifies the index of the first changed item.
targetThe object that dispatched the event. The target is not always the object listening for the event. Use the currentTarget property to access the object that is listening for the event.

See also

preDataChangeevent  
Event object type: fl.events.DataChangeEvent
DataChangeEvent.type property = fl.events.DataChangeEvent.PRE_DATA_CHANGE

Dispatched before the data is changed.

Defines the value of the type property of a preDataChange event object. This event object is dispatched before a change is made to component data.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
changeTypeIdentifies the type of change to be made.
currentTargetThe object that is actively processing the event object with an event listener.
endIndexIdentifies the index of the last item to be changed.
itemsAn array that lists the items to be changed.
startIndexIdentifies the index of the first item to be changed.
targetThe object that dispatched the event. The target is not always the object listening for the event. Use the currentTarget property to access the object that is listening for the event.

See also