4 Replies Latest reply on Aug 24, 2010 12:40 PM by thebouv

    access array in arraycollection and add item to the end of array

    miguel8312 Level 3
      for
      
      
      "login_user":"XXX"},i);
      
      //mess2=sess_MessArr[i2];
      //mess1=dispArray[i2].fwchat_message
      
      //searchArray(mess2);}
      
      
      
      
      
      (var i:int = 0; i< dispArray.length; ++i){
      
      dispArray[i]. 
      dispArray.addItemAt({
      


      I have this code to try to acess the values of the array in the  arraycollection but it does not work it actually creates a value to the end of the arraycollection. can anyone tell me what im doing wrong i basically whant to modifys the individual arrays in the arraycollection and add Login_user

        • 1. Re: access array in arraycollection and add item to the end of array
          miguel8312 Level 3

          sorry everyone my code got messed up above. here is the code again

           

           

          for
          
          
          (var i:int = 0; i< dispArray.length; ++i){
          
          dispArray[i]. 
          dispArray.addItemAt({
          "login_user":"Miguel83"},i);
          
          //mess2=sess_MessArr[i2];
          //mess1=dispArray[i2].fwchat_message
          
          //searchArray(mess2);}
          
          
          
          
          
          • 2. Re: access array in arraycollection and add item to the end of array
            thebouv Level 2

            So, I'm assuming your ArrayCollection is holding an array of objects, like so:

             

            public var myAC:ArrayCollection = new ArrayCollection([{first:"bob",last:"smith"},{first:"jim",last:"jones"},{first:"mary",last:"allen"}]);
            

             

            And you're trying to add in a new property of login_user to each one, right?

             

            for each (var obj:Object in myAC) {
                 obj.login_user = obj.first + "83";
            }
            

             

            Each person would then have first, last and login_user properties.  In my little example above, everyone's login_user would be set to their first name + number 83, so you'd adjust accordingly for  your purposes.

             

            That's the easy way (for each rocks for just such a situation).  However, if you want to stick to the iterative approach you posted, you could try this:

             

            for (var i:int = 0; i < myAC.length; i++) {
                 myAC.getItemAt(i).login_user = myAC.getItemAt(i).first + "83";
            }
            

             

            I think the for each syntax is clearer, but either way works as I think you wanted.

            • 3. Re: access array in arraycollection and add item to the end of array
              miguel8312 Level 3

              dude!!! you are a genius. i neve seem this syntax before with the obj.first + "83"

              I modify your code slightly and it worked like a charm.

               

              here is what i went with.

              THANK you!!!!

               

               

               

              for each

               

               

               

               

               

              (var obj:Object in dispArray) {

              obj.login_user = _user;

              }

               

               

               

               

               

               

               

               

               

               

              • 4. Re: access array in arraycollection and add item to the end of array
                thebouv Level 2

                Glad it worked.  My example was just adding "83" to the end of the first name since I didn't really know your login_name scheme or how you came up with them.

                 

                Have fun programming!