7 Replies Latest reply on Jun 15, 2010 3:31 PM by Flex harUI

    Duplicated entries in Dictionary

    fchen8

      I came from Java to ActionScript so Dictionary object is always a bit strange to me. Today I encountered a weird situation on it which had cost me a few hours of debug time. What I need to do is to find out the common ancestor of two branches in XML. I use Dictionary and the XML node as key. It then all boils down to following snippet:

       

      **********************************

      var project:XML = <project><item id="item1"/><item id="item2"/></project>

       

      var item1:XML = project.children()[0];

      var item2:XML = project.children()[1];

       

      var parent1:XML = item1.parent() as XML;

      var parent2:XML = item2.parent() as XML;

       

      var dic:Dictionary = new Dictionary();

       

      dic[parent1] = "1";

      dic[parent2] = "2";

      **********************************

       

      I expected dic to have only one entry. However it turned out as two entries even though parent1 == parent2 and parent1 === parent2 all test to true. Is this a problem with Dictionary or is it because I used XML as the key and the parent() method whose return type is * is causing the problem? Any help is greatly appreciated! Thanks.

       

       

      Regards,

       

      Feng