1 Reply Latest reply on Oct 18, 2007 7:48 AM by ntsiii

    Need help referencing Objects and ArrayCollections in the same way

    Thᛰr
      Hi all -

      I have an application where I'm using an HTTPService object to pull some XML, which I am then sending to a custom component as an ArrayCollection. The problem is that if there are multiple XML children nodes I get child ArrayCollections. If there is just a single XML child node I get child Objects. For example:

      <xml>
      <widget> ... lots of stuff ... </widget>
      <widget> ... lots of stuff ... </widget>
      <cog> ... lots of stuff ... </cog>
      </xml>
      public function handleIncomingData(event:ResultEvent):void
      {
      data = new ArrayCollection(new Array(event.result.xml));
      }

      When "data" arrives at my component, I get the following ArrayCollection:
      data:ArrayCollection
      data[0]["widget"]:ArrayCollection
      data[0]["widget"].length == 2;
      data[0]["cog"]:Object
      data[0]["cog"].length == 0;

      Sometimes I may get many <cog>s, and so I need to be able to treat it like an array. But in the case where there is just one, it arrives as an object instead of as an ArrayCollection with a single element.

      Is there any way to fix this? Is there a better way to reference my data hierarchy?

      Thanks