Home > Adobe Flex > Adobe Flex ComboBox DataProvider

Adobe Flex ComboBox DataProvider

January 30th, 2011 Leave a comment Go to comments

In this simple example I will show you how to use the ComboBox component in Flex. We will create an ArrayCollection with items which we will use as a dataProvider for the comboBox. Below you can see the working code for this example.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

 <mx:Script>
 <![CDATA[
 import mx.collections.ArrayCollection;

 [Bindable]
 private var comboBoxDataProvider:ArrayCollection = new ArrayCollection(["One", "Two", "Three", "Four"]);

 ]]>
 </mx:Script>

 <mx:ComboBox id="comboBox" dataProvider="{comboBoxDataProvider}" />

</mx:Application>

As you see, we created the ComboBox component and as a dataProvider we set the ‘comboBoxDataProvider’ variable. It is from type ArrayCollection and it is declared as Bindable. The [Bindable] Meta tag in Flex allows you to map an object or value to a property. It is also know as data binding. Next, in the constructor of our ArrayCollection we create an array of strings:

new ArrayCollection(["One", "Two", "Three", "Four"]);

This is enough. Now we have a comboBox component with 4 elements.

Liked this tutorial? Share and Enjoy:

  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Reddit
  • blogmarks
  • StumbleUpon
  • Technorati
  • TwitThis
  • Yahoo! Buzz
  • NewsVine
  • Slashdot
  1. No comments yet.
  1. No trackbacks yet.