1 Reply Latest reply on Feb 16, 2007 8:25 AM by FlightGuy

    Array Collections

    nprzybylo Level 1
      I am trying to append data to a given item in an array collection. What I want to do is something like:

      myArrayCollection.addItemAt({var1:"hello"},0);
      myArrayCollection.addItemAt({var2:"goodbye",0);

      When I add var2 to the first index, it overwrites the entire object that is there, so var1 has no value. I want to make it so that var1 and var2 are separately added to the first item without the second addition overwriting the entire object. Any advice would be greatly appreciated.
        • 1. Re: Array Collections
          FlightGuy Level 1
          You need to have an item first:
          myArrayCollection.addItemAt(new Object(), 0);

          Then you can retrieve the object and add dynamic properties:
          myArrayCollection.getItemAt(0).var1 = "hello";
          myArrayCollection.getItemAt(0).var2 = "goodbye";

          No point in using the ArrayCollection, of course, if you're only using one entry. For that you can just use an object.

          Alternatively:
          var myObject:Object = myArrayCollection.getItemAt(0);

          myObject.var1="hello";
          myObject.var2="goodbye";

          Tim