Follow Flex After Dark on Twitter

Flex Data Providers

Several Flex components, including all list-based controls, display data from a data provider, a collection or object that contains the data displayed by the control.

The data provider concept creates a level of abstraction between components and the data used to populate them. You can think of the data provider as the model, and the Flex components as the view of the model. By separating the model from the view, you can change one without changing the other.

Data-driven components enable the ability to:

  • Switch data providers for a component at run-time
  • Share the same data provider among multiple components
  • Modify a data provider so that changes are reflected by all components that use it

Controls that display application data via a dataProvider property are often referred to as data-driven controls.

Common controls that get their information from data providers:

Objects commonly used as data providers:

  • Array - an array is a simple data provider, but with some shortcomings
  • Collection - a collection is a more robust data provider with binding capabilities
  • XML - XML...

Arrays as Data Providers

An Array can be used a data provider. Arrays are best used for static (non-changing) or inline data providers.

   <mx:ComboBox prompt="Is this a ComboBox?">
      <mx:dataProvider>
         <mx:Array>
            <mx:String>Yes</mx:String>
            <mx:String>No</mx:String>
            <mx:String>Maybe</mx:String>
         </mx:Array>
      </mx:dataProvider>
   </mx:ComboBox>

This example shows an array of strings being used as an inline, static data provider.

If you use a raw data object, such as an Array, as a control's data provider, Flex automatically wraps the object in a collection wrapper. However, the control does not automatically detect changes that are made directly to the source object.

Collections as Data Providers

Collections are ideal data providers because when the contents of a collection change, controls using the collection as a data provider are automatically updated.

Learn more about Collections and their use as data providers...

XML as Data Providers

TODO...

Learn more about XML...

Item Renderers

Flex components that use Data Providers often also use Item Renderers for displaying each item.

Item Renderers...

Related Links:

Related Docs
  • Flex DataGrid The Flex DataGrid control is used for displaying tabular data.
  • Flex Item Renderers A Flex Item Renderer is a component used by data-driven controls, including lists, for displaying each item of a data provider.
  • Flex List Controls Flex List controls refer to a special group of controls that display collections of items, usually from a data provider.
  • Flex Collections Collections are objects that provide a uniform way to access and represent item lists.
Recent Docs
  • Flex Data Providers Several Flex components, including all list-based controls, display data from a data provider, a collection or object that contains the data displayed by the control.
  • Flex Item Renderers A Flex Item Renderer is a component used by data-driven controls, including lists, for displaying each item of a data provider.
  • Flex Progress Bar The Flex Progress Bar control is used for displaying progress to users.
  • Flex Builder Overview Overview of FlexBuilder, Adobe's integrated development environment (IDE) for Flex development.
  • ActionScript Dynamic Objects Dynamic objects in ActionScript can be created with arbitrary properties and functions at run-time.
Random Docs