Adobe Flex ComboBox DataProvider
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.




