Flex Bindable Hash

For the Dunelox library, I needed a simplified Flex version of the Spring ApplicationContext which is a generic Hash object containing model objects accessed by a key (String). Visual components that are wired to these models objects need to be updated automatically using the standard event mechanism in Flex.

So, I had a look at the standard ArrayCollection to find out how it notifies components that are wired to elements by index. This gave me the idea to implement the HashCollection as a extension to this class.

If you need to wire a value by key in a component such as:

<mx:TextInput text=“{hash.get(‘somekey’)}” />

And you declare the variable hash as a HashCollection like this:

[Bindable] public var hash:HashCollection = new HashCollection()

Then your component is updated if you change the value associated to that key:

hash.put(‘somekey’, ‘changed the value of somekey’ )


Update: have a look at the source code

comments powered by Disqus