4 Replies Latest reply on Aug 6, 2008 7:52 AM by Newsgroup_User

    Array vs ArrayCollection

    Gregory Lafrance Level 6
      I've often heard you create an Array and then wrap it in an ArrayCollection, to take advantage of binding. But why not always just use an ArrayCollection? Array has push(), myArray[index], etc. and ArrayCollection has addItem(), etc.
        • 1. Re: Array vs ArrayCollection
          Level 7

          "Greg Lafrance" <glafrance@chikaradev.com> wrote in message
          news:g7aneh$pjh$1@forums.macromedia.com...
          > I've often heard you create an Array and then wrap it in an
          > ArrayCollection, to
          > take advantage of binding. But why not always just use an ArrayCollection?
          > Array has push(), myArray[index], etc. and ArrayCollection has addItem(),
          > etc.

          I think the ArrayCollection is slightly heavier and so will have slightly
          slower performance. If you use ArrayCollection, I believe both Array and
          ArrayCollection get compiled into the swf, which will of course make the
          file size larger.


          • 2. Re: Array vs ArrayCollection
            Karl_Sigiscar_1971 Level 3

            Even when you do not create an ArrayCollection from an Array, as in the example below, the underlying implementation still creates an array.

            var exampleAC:ArrayCollection = new ArrayCollection();
            var item:someTypeDTO;
            exampleAC.addItem(item);
            • 3. Re: Array vs ArrayCollection
              Gregory Lafrance Level 6
              I understand these points. What I am wondering is from a coding standpoint, is there any reason to create an array first and then wrap it in an ArrayCollection, meaning are there things you might want to do on the Array, which would then get propagated into the AC, but which are more difficult or impossible to do directly on an AC?
              • 4. Re: Array vs ArrayCollection
                Level 7

                "Greg Lafrance" <glafrance@chikaradev.com> wrote in message
                news:g7ccno$mju$1@forums.macromedia.com...
                >I understand these points. What I am wondering is from a coding standpoint,
                >is
                > there any reason to create an array first and then wrap it in an
                > ArrayCollection, meaning are there things you might want to do on the
                > Array,
                > which would then get propagated into the AC, but which are more difficult
                > or
                > impossible to do directly on an AC?

                Sometimes people manipulate the array and then reset the source for the AC
                if they don't want the changes to propogate in the UI in any controls that
                are using the AC as a dataProvider.