2 Replies Latest reply on Aug 24, 2010 8:40 AM by miguel8312

    compare arraycollections

    miguel8312 Level 3

      hello guys

      im trying to compare two array collections but im having a nightmare doing it.

      here is my code so far but icat seem to bring it home. basically when i find a difference withing one array compare to the other i like to change the  value at a specific index of the collection

      var mess1:String = new String();
      
      var mess2:String = new String();
      
      //compare the two arrays and decide wether it came from this seession or the outside.
      
      
      for(var i:int = 0; i< dispArray.length; ++i){                     mess1=dispArray[i].fwchat_message
      
                          };
      
      
      
      for(var i2:int = 0; i2< sess_MessArr.length; ++i2)     
                     {
                          mess2=sess_MessArr[i2];
      
      
      
      
      if(mess1!=mess2){trace(mess1 + "" + mess2 + "" + 'are not equal')}
      
      
                     }        
      
      
      
      
      


      any help would be greatly appreciated.

      Miguel

        • 1. Re: compare arraycollections
          betheflexcoder Level 2

          If you are using an array collection,





          private function compareArrayCollections():void

          {
          for(var i:int = 0; i< dispArray.length; ++i){  

           

                         mess1:String =dispArray.getItemAt(i) as String;

                            if( !checkInSession(mess1))

                             trace(mess1 + "" + mess2 + "" + 'are not equal';

           

                              };

          }


          private function checkInSession(message:String): Boolean

          {

               var flag:Boolean = false;
                    for(var i2:int = 0; i2< sess_MessArr.length; ++i2)    
                         {

                              mess2=sess_MessArr.getItemAt(i) as String;

                    if(message == mess2)

                    {

                         flag = true;

                          break;

                    }

               return flag;

                             }

          In case of arraycollection, instead of a separate method like above to checkInSession, you can use sess_MessArr.contains(mess1) which returns boolean.

           

          If you are using array and not arraycollection, get the item like sess_MessArr[i]




          • 2. Re: compare arraycollections
            miguel8312 Level 3

            thanks really appreciated your help on this one!!!

            Miguel