This is something I must have overlooked, and hence thought other people may have also overlooked it. It’s quite simple really.
During the initial creation of my Inhouse application I had been using the Combobox with a function within the same mxml file to allow me to use a selectedValue. Something like….
<mx:ComboBox
id="mycombo"
width="269"
tabIndex="5"
dataProvider="{mycodes}"
selectedIndex="{getSelectedIndex(mycode,mycodes)}"
styleName="topcombobox"
/>
So, rather than write my own custom component decided it was time to utilize the fantastic resources available. After a quick search to some areas where I had seen this demonstrated before I came across an article written by the one and only Ben Forta on ComboBox and Selected Values. Link Below.
http://www.forta.com/blog/index.cfm/2006/11/22/Flex-ComboBox-With-selectedValue-Support
So, this is where my problems began, not really sure why I haven’t come across this before, infact I think I have, but my brain has been so off track with the holidays and all, its time to get back on track.
So if you view ben’s article the magic function causing the problem for me was
override public function set dataProvider(o:Object):void
Why a problem you ask? because the object being passed to the function is the value that helps us notify the custom component that there are records waiting to be searched ie.
if (o!=null && o.length)
{
// Got it, set flag
bDataProviderSet = true;
}
The value that I was getting was an empty ArrayCollection, although it seemed that it couldn’t be true because the values were appearing in the ComboBox’s list. The cause of this is that the set method is fired when the collection is created or set in the model. When records are then added, removed or updated within this collection another function is called “collectionChangeHandler”. The combobox was being updated, but the custom component wasn’t working. In my program the ArrayCollection being created had some additional processing logic.
Not sure if I’m following best practices, but in the situation where you are manually building the ArrayCollection for what ever the reason maybe. For the bindings to work as you would like them to, create a temporary Array and then re create the ArrayCollection like so.
mymodel.mycodes = new ArrayCollection(tempArray);
Once I had done this, the custom control worked perfectly. Hopefully I didn’t get to off track with this post, and hopefully it helps at least one person that may have had this confuse them.
Cheers
Gareth.