views:

245

answers:

2

I am using a combobox for the us states, link. The label is set to the full name of the state, while the value attribute holds the abbreviation. What I want to do is to get the selected item's value. So I tried combo.selectedItem.value and combo.selectedItem.@value, but neither of them worked. Can someone shed a light on this please?

A: 

You can populate an array with the values you want to get and retrieve the index of the selected item on the combo box (which should be the same as in the array).

Or in your component ... just look for the index (selected item) child on statesUS

Diego Dias
Thanks. statesUS is a private property of the combobox, I don't think I can access it directly. Could you be more specific?
Tong Wang
You are right .. I haven't paied attention it was a private variable... anyway, this is like a constant array, so there will be no problem if you make a get function.
Diego Dias
+1  A: 

Here's a simple example that might be helpful.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
 <mx:ComboBox id="comboBox" dataProvider="{[{label:'California', value:'CA'}, {label:'New York', value:'NY'}]}" />
 <mx:Label text="{comboBox.selectedItem.value}" />
</mx:Application>


Here's another example. In this one we use XML as dataProvider.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
    <mx:XML id="xml" xmlns="">
     <states>
            <state label="Alabama" value="AL" country="US" />
            <state label="Alaska" value="AK" country="US" />
            <state label="Arkansas" value="AR" country="US" />
        </states>
    </mx:XML>
    <mx:ComboBox id="comboBox" dataProvider="{xml.state}" labelField="@label" />
    <mx:Label text="{comboBox.selectedItem.@value}" />
</mx:Application>
Emanuil
Thanks, this works. Just for my knowledge, I still like to find out how to get the selected item's value if I have XML as the dataProvider, like the one shown in my original post's link.
Tong Wang
Just edited my answer to include an example where XML is used as dataProvider.
Emanuil