views:

2487

answers:

1

One of the things I miss the most in ActionScript is the lack of operator overloading, in particular ==. I kind of work around this issue by adding a "Compare" method to my classes, but that doesn't help in many cases, like when you want to use things like the built in Dictionary.

Is there a good way to work around this problem?

+5  A: 

Nope.

But it doesn't hurt to add equals methods to your own classes. I try to never use == when comparing objects (the same goes for ===, which is the same thing for objects) since it only checks identity .

Sadly all the collections in Flash and Flex assume that identity is the only measure of equality that is needed.

There are hints in Flex that someone wanted to alleviate this problem at one time, but it seems like it was abandoned: there is an interface called IUID, and it is mentioned in the Flex Developer's Guide , but it is not used anywhere. Not even the collections in Flex use it to determine equality. And since you are asking for a solution for Flash, it may not have helped you anyway.

I've written some more about this (in the context of Flex) on my blog: Is there no equality?.

Theo