4 Replies Latest reply on Feb 8, 2008 12:45 PM by ntsiii

    ArrayCollection equal ?

    mark416 Level 1
      I have two ArrayCollection,

      May I use ac1=ac2?

      Thanks

      Mark
        • 1. Re: ArrayCollection equal ?
          Gregory Lafrance Level 6
          This code seems to indicate you can:
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init()">
          <mx:Script>
          <![CDATA[
          import mx.collections.ArrayCollection;
          private var ac1:ArrayCollection = new ArrayCollection(["One","Two","Three"]);
          private var ac2:ArrayCollection = ac1;

          private function init():void{
          trace(ac2);
          }
          ]]>
          </mx:Script>
          </mx:Application>
          • 2. Re: ArrayCollection equal ?
            Arty13
            FYI -
            I think if you do the above code, I believe you will only have 1 array collection but have 2 different variables pointing at it.

            I'm not 100% sure about this, but keep that in mind.

            Art
            • 3. Re: ArrayCollection equal ?
              gtb104
              If you're asking if you can assign ac1 to ac2, then yes, ac1=ac2 will work. You will only have one ArrayCollection instance(the one that is defined by ac2), but you will have 2 pointers to it. This means that if you manipulate ac1, ac2 will show the same changes since they're pointing to the same ArrayCollection.

              If you're asking if the content of two ArrayCollections (ac1 and ac2) are equivalent, then no, that will not work. I don't believe there are any built in methods to compare two different instances of ArrayCollections for equivalency.
              • 4. Re: ArrayCollection equal ?
                ntsiii Level 3
                the "===" operator will tell you if two variables point to the same instance of an object.
                Tracy