views:

158

answers:

1

I want to load key/values configuration pairs stored in XML file. To bind a collection of data i know i need to use the ArrayList class, but the problem is that i want to be able to bind the loaded values using their corresponding keys and not by their indexes in the ArrayList object.

For example i want to be able to do this :

<mx:Text id="errorText" text="{Config.params['someKey']}" />

instead of :

<mx:Text id="errorText" text="{Config.params[0]}" />

where Config.params is ArrayList (obviously i couldn't use ArrayList since it doesn't allow selecting a value by key)

So the question is how to bind the key/value pairs loaded form XML. I don't want to go manually set variables, i want to bind them so when they are loaded the are set automatically. Did anyone had to do something like that ?

A: 

I would suggest using a Dictionary in place of your ArrayList. If I understand your question correctly this would enable you to do exactly what you wrote in the first snippet:

<mx:Text id="errorText" text="{Config.params['someKey']}" />

Good luck!

====== Edit ======

Here's an example of using e4x in binding expressions: binding with e4x

heavilyinvolved
You could also use a generic Object for an associate array.
heavilyinvolved
A far as i know Dictionaries and Generic Objects are not bindable in Flex.
Hichem
Ah, right. Have you considered using e4x notation in your binding expressions? See my edit...
heavilyinvolved