I am dynamically populating a ComboBox with an HTTPservice calling an XML file. This all works dandy through the Flash Build 4 interface. Below is the ComboBox code:
<s:ComboBox id="cbSockOptions" change="cbSockOptions_changeHandler(event)"
selectedIndex="1"
enabled="true"
creationComplete="cbSockOptions_creationCompleteHandler(event)"
labelField="Symbol">
<s:AsyncListView list="{TypeUtility.convertToCollection(Operation1Result2.lastResult.Company)}"/>
</s:ComboBox>
As stated, above is my code which populates the ComboBox. I would like to retrieve the seleted value from the ComboBox, but when I do I get the following output (e.g. when presented in a Label):
[object Company_Type]
I am currently using the following code to retrieve the value of the ComboBox
cbSockOptions.selectedItem;
All the reading I have done on the subject says that I must specify a ‘labelField’ in my ComboBox, which I do. However, I am still seeing the [object Company_Type] as an output, instead of the real value.
help! 🙁
The labelfunction property only applies to displaying values in the ComboBox. There is a selectedLabel property of the ComboBox, but it is not marked as bindable. If you want to use the selectedItem elsewhere, you’ll have to access the properties directly.
Going from simple to complex, you could try
But I think you’ll get binding warnings if you do that because of the array accessor – and it is never good to cause warnings.
A better idea would be to cast the selectedItem to the same type as the items in the collection created by TypeUtility.convertToCollection, e.g.
The best idea would be to use your cbSockOptions_changeHandler to set a local variable (e.g. selectedCompany) to use for binding. If your classes is Bindable, then you could just used the selectedCompany
otherwise if the class is not bindable, then you could just use another property to store the value