Search code examples
apache-flexprogramming-languagesarraycollection

Why does Flex's ArrayCollection's Contain method look at memory reference?


When using .contains() on an ArrayCollection in Flex, it will always look at the memory reference. It does not appear to look at an .equals() method or .toString() method or anything overridable. Instead, I need to loop through the ArrayCollection every time and check each individual item until I find what I'm looking for.

Does anyone know why Flex/ActionScript was made this way? Why not provide a way from people to use the contains() method the way they want?


Solution

  • Well, it seems like the ArrayCollection doesn't actually look directly at memory, but only as a last resort. It will attempt to find a Unique ID (UID) for the object. If the UID doesn't exist, it will create one for it using the UIDUtil.as.

    You can get around this whole default UID stuff by having your object implement the IUID interface and providing your own UID for the object. The ArrayCollection will look at the UID you provide it.