How can I make a value-aware combo box in Flex 4?
Combo boxes in Flex are really awkward to use if you have objects in them addressed by properties, in my experience. In Flex 3.5 we had a working extension to the combo box that would populate a selectedValue
property (and allow changing the selectedIndex
by same).
Here's a quick example of what using one of these looks like:
<c:ValueComboBox valueField="country_code">
<mx:Script>
<![CDATA[
public function get selectedCountry(): String {
return this.selectedValue; // This property is added by ValueComboBox
}
public function set selectedCountry(v: String): void {
this.selectedValue = v;
}
]]>
</mx:Script>
<c:dataprovider>
&l开发者_如何学JAVAt;mx:ArrayCollection>
<mx:Object label="Canada" country_code="ca"/>
<!-- ... -->
</mx:ArrayCollection>
</c:dataprovider>
</c:ValueComboBox>
However, this has stopped working in Flex 4. What's happening is that our existing component drove its changes by overriding the set selectedIndex()
function, which is no longer called when the combo box's selected index changes (wtf?).
Is there a working value-aware combobox implementation for Flex 4?
For information purposes, here is the base value combo box class. https://gist.github.com/5639c7b2439b03748e2e
Flex 4 ComboBox now uses userProposedSelectedIndex
property to store temporal value of selected index till ComboBox closes. And then selectedIndex property doesn't set with selectedIndex
but with calling of setSelectedIndex
method with the following signature:
mx_internal function setSelectedIndex(value:int, dispatchChangeEvent:Boolean = false):void
I suggest you should override this method to make sure selected index is setting properly.
Hope this helps.
精彩评论