Sometimes there are things so powerfull that thay have problems just for being powerfull, that’s what happens with HaXe sometimes.
There is not a Dictionary class officialy supported by HaXe, the TypedDictionary class only works on the Flash target.
The reason is because HaXe creates native code, and there is not a generic way in all the native platforms to get an identifier of an object.
But that doesn’t mean we can’t have a a Dictionary class so here it is my version of it, called ObjectHash.
Works good and fast like the flash class, at least on the targets I have tested it: flash, windows/C++ and html5 . If you tested it in another target let me know, I’ll update this.
How to use it:
It has the same syntax of TypedDictionary. If you need to know how to use the class, learn TypedDitionary.
Differences with NME’s ObjectHash:
- The NME’s class is more efficient with virtual memory.
- This class supports more targets than NME’s one.
- This class works like TypedDictionary or like Dictionary in AS3, when you make a loop you get the keys. NME’s ObjectHash behaves in consistency with HaXe’s Hash, when you make a loop you get values so you need to make a loop using objectHash.keys() to get the keys.
If you are targeting only the NME platforms I recommend you to use that class.
There are some small limitations:
String, Float, Int and Bool types can be set as values but not as keys. Example: myObjectHash.set(myInt, myMovieClip) doesn’t work and myObjectHash.set(myMovieClip, myInt) works. I think is not a big problem since using those basic data types as keys in a object hash is a rare case, I never needed to do that in my years of AS3 development. NME’s version of the class has the same limitation for the moment.