I’m sure most of you would have come across the Dictionary class in your adventure that is AS3.0. If you haven’t, here’s a brief introduction.
In AS3, the new Dictionary class is introduced (under the flash.utils package). Similar to the Array, it uses Object Keys instead of Numeric Keys. This does give the developer more tools to work with something like path-finding, for example. Using Object Keys to signify that a specific point has been calculated:
1 | myDictionary[x_y] = true; |
One can simply pile objects onto the Dictionary, and pull out data using Objects as references. Where as with the old Array() method, one had to check through the entire array for a specific Object in a “hasChecked” array. This saves lots of time.
Anyway, I was recently working with the Dictionary object in a project. By loading an XML file, I had a dynamic list of strings to work with. And I used those strings as Keys in the Dictionary for access. However, when I tried to access the Keys as strings, it wouldn’t work.
This, I found out, was because the Dictionary class uses === (strict equality); you must input the exact reference. In this case, it was the string in my XML object.
How I got about this was simply using the String constructor. Since the Dictionary class also accepts String objects, you could use a similar String to compare values. Thus where
1 | myDictionary[myXML.val] |
would have failed, this would work:
1 | myDictionary[String(myXML.val)] |
Hope someone out there might find this useful in the event they run into such a situation.






I’m glad someone posted this. The “converting to a string” tip saved me who knows how long.
Hehe, upon reading this post again, I realise that I got strict equality mistaken?
=== above should mean that the class types must be the same, not just the equivalent values. Thus the requirement to create a string out of the xml value.