4 Replies Latest reply on Feb 8, 2008 9:21 AM by dubbeat

    arrayCollection Manipulation

    dubbeat Level 1
      Hi,

      I'm using an arrayCollection to read in a complex XML file. Im seeking advice on how to "chop up" the array collection.
      I was also considering using E4X instead but I've heard theres not a lot of browser support?

      Anyway, for example my XML files that Im reading will not have a fixed amount of elements etc. Here is an example of what the XML looks like.


      <ClipMediaItemList>
      <clipMediaItem>
      <data> blah blah blah </data>
      <data> blah blah blah </data>
      <data> blah blah blah </data>
      <clipMediaItem>
      <clipMediaItem>
      <data> blah blah blah </data>
      <data> blah blah blah </data>
      <data> blah blah blah </data>
      <clipMediaItem>
      </ClipMediaItemList>


      In my XML there will be an unknown number of "clipMediaItems".

      Im really looking on advice on

      1) Would arrayCollection or E4X suit this best?

      2) How would I go about counting the number of <clipMediaItem> , then create some kind of container for each one, and fill each container with <data>.

      Im pretty new to flex so even a pseudo code help or a point in the right direction to a tutorial would be great. Im just not really sure what I'm looking for.

      Thanks,
      dub


        • 1. Re: arrayCollection Manipulation
          Arty13
          I personally would use E4X,
          look at the XML Class in Adobe Live Docs, they should have examples on what you want to do as well.

          Hope this helps you out.

          Art
          • 2. Re: arrayCollection Manipulation
            dubbeat Level 1
            Im a bit lost.

            Would clipMediaItem be a child node of ClipMediaItemList? And if it is how can I count them and make seperate objects for each one?



            for each (var ClipMediaItem:XML in bookStock.ClipMediaListItem.ClipMediaItem)
            {

            count++;
            }




            Is the above completely silly or am I on the right track?

            Thanks again
            • 3. Re: arrayCollection Manipulation
              Arty13 Level 1
              try something like this...

              ***********************

              var myXML:XMLList = new XMLList(
              <ClipMediaItemList>
              <clipMediaItem>
              <data> blah blah blah </data>
              <data> blah blah blah </data>
              <data> blah blah blah </data>
              </clipMediaItem>
              <clipMediaItem>
              <data> blah blah blah </data>
              <data> blah blah blah </data>
              <data> blah blah blah </data>
              </clipMediaItem>
              </ClipMediaItemList>);

              var childrenCount:int = myXML.children().length();

              Alert.show(String(childrenCount), "child Count");

              *********************

              you could access the children by doing this... myXML.clipMediaItem[0] (in your loop) and that will return the data values for index 0 (first child) of your myXML children as an XMLList and you can do what you want with those values.
              If you need to access specific values from your children, you can do myXML.clipMediaItem[0].data[0]

              Hope this helps you out some, just look at the Adobe Live help for more tips on XML processing.

              Art
              • 4. Re: arrayCollection Manipulation
                dubbeat Level 1
                Thanks Art.

                Its a good start for me

                :)