
140 Use List-based Form Controls
If you want to access the value of the selected item in the ComboBox control, you can use
the following expression in your code:
cbxRating.value
In this example, the value property of the ComboBox control (cbxRating.value) could
contain Satisfied, Neutral, or Dissatisfied.
4. To test the control, insert the following tag after the <mx:Button> tag in the
ListControl.mxml file:
<mx:Label x="20" y="120" text="{cbxRating.value}" />
The resulting application should look like the following:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Panel x="10" y="10" width="350" height="200" title="Rate Customer
Service">
<mx:ComboBox id="cbxRating" x="20" y="20" width="100">
<mx:dataProvider>
<mx:Array>
<mx:String>Satisfied</mx:String>
<mx:String>Neutral</mx:String>
<mx:String>Dissatisfied</mx:String>
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
<mx:Button x="140" y="20" label="Send"/>
<mx:Label x="20" y="120" text="{cbxRating.value}"/>
</mx:Panel>
</mx:Application>
The expression inside the curly braces ({ }) is a binding expression that copies the value of
the ComboBox control’s
value property, cbxRating.value, into the Label control’s text
property. In other words, the
text property of the Label control is specified by the value
of the selected item in the ComboBox control.
5. Save the file, wait until Flex Builder finishes compiling, and run the application.
Select items in the ComboBox. The Label you inserted displays Satisfied, Neutral, or
Dissatisfied depending on your selection.
Associate values with list items
You may want to associate values with list items in a form control in the same way you
associate values with the SELECT form element in HTML. For example, to generate reports
and statistics, you might want to associate the value of 5 with Satisfied, 3 with Neutral, and 1
with Dissatisfied.
Commenti su questo manuale