0 Replies Latest reply on Nov 6, 2006 11:07 AM by brentbordelon

    Help! Trouble with single items in for...each loop using HTTPService

      I'm just starting out with Flex 2/ActionScript 3, and I'm having a real
      problem trying to loop through results returned from an HTTPService (in
      XML format) when there is only one row of data. Here's what I have:

      ------------------------------------------------------------------------------------------ ------------------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute" creationComplete="Results.send()">
      <mx:HTTPService url=" http://mysqlserver/test?sql=EXECUTE+usp_Test"
      id="Results" showBusyCursor="true" result="ShowData()"/>

      private function ShowData():void {
      for each (var row:Object in Results.lastResult.items.item) {
      DataItemList.text += row.id + "\n";

      <mx:Text x="10" y="10" width="100%" height="100%"

      ------------------------------------------------------------------------------------------ ------------------------------------

      Now I get exactly what I'd expect when the http service returns more
      than one row, like this:

      <item id="Item One"/>
      <item id="Item Two"/>

      But if there is only one row, like this...
      <item id="Item One"/>

      ...I get a "ReferenceError: Error #1069: Property id not found on
      String and there is no default value."

      It appears that the for/each loop is broken? I've looked around and
      seen references explaining that a single row is returned as a different
      data type (object) than multiple rows (ArrayCollection). Is this true?

      I'd like a method that would return the same data type regardless of
      the number of rows. Any help would be greatly appreciated.