Fx{r} is trying to start the Fx{r} Community! Please join our group on Adobe Groups following this link: http://groups.adobe.com/groups/ab29539ab9.
Fx{r} is now on Twitter too. Follow us @ twitter.com/fx_r!
«
»

ActionScript, Flex 2

Compare two objects

Virgil Cristea | 07.11.07 | 4 Comments

Google Buzz

If you ever wondered how can you compare 2 objects (big structure objects that can not be compared by Flex itself using the === operator) in Flex to find out if they are identically the same one of the methods used were to check all their attributes.

Another much better and faster method is this:

public function compareObject(obj1:Object,obj2:Object):Boolean
{
    var buffer1:ByteArray = new ByteArray();
    buffer1.writeObject(obj1);
    var buffer2:ByteArray = new ByteArray();
    buffer2.writeObject(obj2);
 
    // compare the lengths
    var size:uint = buffer1.length;
    if (buffer1.length == buffer2.length) {
        buffer1.position = 0;
        buffer2.position = 0;
 
        // then the bits
        while (buffer1.position < size) {
            var v1:int = buffer1.readByte();
            if (v1 != buffer2.readByte()) {
                return false;
            }
        }    
        return true;                        
    }
    return false;
}
Share and Enjoy:
  • Twitter
  • Google Buzz
  • LinkedIn
  • Google Bookmarks
  • del.icio.us
  • Digg
  • Sphinn
  • blogmarks
  • Reddit
  • StumbleUpon
  • Facebook
  • DZone
  • FriendFeed
  • Yahoo! Buzz
  • Yahoo! Bookmarks
  • Slashdot
  • MySpace
  • Add to favorites




Tags: , ,

This post was written by Virgil Cristea

Views: 5586

related

4 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

:

:


«
»