views:

45

answers:

3

I have a Dictionary that I'd like to bind as the dataProvider for an mx:ComboBox. e.g., when I do this:

       mydict[somenewkey]= somenewval;

I'd like the combobox to update its contents.

The problem is that Dictionary doesn't seem to be Bindable. If I were using an Array, I'd use ArrayCollection. But there doesn't seem to be a corresponding DictionaryCollection or HashCollection. What to do?

A: 

Try using an ObjectProxy:

http://www.adobe.com/livedocs/flex/3/langref/mx/utils/ObjectProxy.html

aeflash
can you elaborate?
paleozogt
+1  A: 

A Dictionary is not the appropriate object for a dataProvider of a list based class.

I suspect your display problems have nothing to do with data binding, but rather other issues, such as a dictionary does not have a length property.

I suspect the ComboBox will treat your dictionary as a single object, not as a collection of multiple objects.

www.Flextras.com
What would be an appropriate object to use?
paleozogt
I strongly recommend using a collection class, although you can also use Arrays, XMLList, or straight XML.
www.Flextras.com
The problem is that those collections don't have key=>value semantics.
paleozogt
Very true. Why do you need that? I guess, in theory, you could extend the ComboBox / List Class to accept a Dictionary as the dataProvider; but I'd hope you'd have a strong user case for doing so.
www.Flextras.com
A: 

Isn't what you're looking for just a combination of the setItemAt and getItemIndex methods of the ArrayCollection?

_myAC.setItemAt( somenewval, _myAC.getItemIndex( somenewkey ) );
Gareth Arch