3 Replies Latest reply on Jun 5, 2010 1:47 PM by UbuntuPenguin

    Object equality/pointer comparison

    jsd99 Level 3

      I am traversing an mx:Repeater.  Each child in the repeater has an "item" property.  At some point, one of the children will fire an event.  When the event is dispatched, I want to do something to all the other children (but not the one that sent it).  I made a custom event subclass called EventWithObject.  I'm attaching the child object to the event when sending it.  In the receiving class, I need to iterate over the repeater's children and find the ones that DON'T match the object.  I need to somehow compare the objects in the repeater to the object that was sent in the event.  So far I have had no luck with this.  == doesn't work. === doesn't work.  obj1.valueOf() == obj2.valueOf() doesn't work.  They actually trigger errors in the framework, which is disturbing.

       


      How do you actually do this?

        • 1. Re: Object equality/pointer comparison
          Flex harUI Adobe Employee

          == or === will work if you are in fact comparing the right things.  The

          dispatcher of any event is in event.target so there shouldn't be a need to

          also add the child to an event object.  In most cases, a handler will then

          just do:

           

          If (event.target == this) return;

          • 2. Re: Object equality/pointer comparison
            jsd99 Level 3

            Well, the debugger said they were the same thing, but I was getting an error.  I don't know.

             

            I thought of another way to do it: using a singleton object to "share" an event among all the children.  This is working now and it keeps all the logic inside the children, which is probably a better design anyway.

            • 3. Re: Object equality/pointer comparison
              UbuntuPenguin Level 4

              ...singleton...better design , does not compute.

              Anyway , you could just store the value object the repeater is iterating over in the event.  Then when you handle the event , you just iterate over the dataProvider given to the repeater.  That way you are just doing a simple object comparison.

               

              <Repeater dataProvider="{voCollection}">

                <CustomComponent vo={repeater.curren..forgot the rest}

               

              <CustomComponent>

                <Script>

                  [Bindable] public var vo:ValueObject;

               

               

                  function sendEvent():void

                  {

                     var repeatEvent:Event = new RepeatEvent();

                     repeatEvent.vo = vo;

                  }

               

              This is where you handle the event.

               

              var voCollection:ArrayCollection;

              function handleRepeatEvent( event:RepeatEvent ):void

              {

                for each  ( var object:Object in voCollection )

                {

                  if( event.vo = object )

                  {

                    trace("foo");

                  }

                }

              }