Flex and Dictionary class

Today I have had the opportunity to play a lot with Flex and the Dictionary class.

In ActionScript 2.0 when i needed something very simple to hold my data, I used pure Objects or their subclasses with bunch of methods, now we have more specialized class for this – flash.utils.Dictionary.
The Dictionary class lets you create a dynamic collection of properties, which uses strict equality (===) for key comparison on non-primitive object keys.

What I need today was a class able to handle a Dictionary in order to solve this tasks:

  1. The items added to Dictionary needs to auto define their key
  2. The class needs to keep a reference to a Class used as a “map” in order to be sure that when I search for a specific property inside the items I’m not making a mistake
  3. Return the value of a specific property of an item
  4. Get a list of all the items stored in the dictionary

The result is a class named DictionaryUtility that get a class definition, maps this definition to an object exploring the accessor methods and the public property of the class and that create a Dictionary dinamically.
In order to get the class definition I have used the utils package

In order to recover the items collected in the Dictionary I used a simple for…in loop and the ArrayCollection class

The sample is available here and the source is here, I hope that someone may get some inspiration or help from this.

Comments

comments

Leave a Reply

Your email address will not be published.


*