1 Reply Latest reply on Jun 9, 2007 10:54 PM by chris.huston.t10

    How to determine size of result object?

    seattlemike
      How can one determine the size of the result object? I need to know how many times to iterate through a result object.

      Alternatively, would like to use for...each but doesn't work for me -- only iterates through once and stops. Here's my code:

      for each ( evt.result.root.offeringRoot in evt.result.root ){
      myArray.addItem( {offeringName:evt.result.root.offeringRoot.offeringName, offeringNumber:evt.result.root.offeringRoot.offeringNumber, offeringID:evt.result.root.offeringRoot.offeringID, offeringType:evt.result.root.offeringRoot.offeringType, offeringDate:evt.result.root.offeringRoot.offeringDate, offeringTime:evt.result.root.offeringRoot.offeringTime} );
      }

      The XML coming back in the result object (as type Object) is:
      <root>
      <offeringRoot>
      <offeringID>1</offeringID>
      <offeringName>Math 101</offeringName>
      <offeringType>Live Class</offeringType>
      <offeringDate>01/01/2007</offeringDate>
      <offeringTime>8:00 AM</offeringTime>
      </offeringRoot>
      .
      .
      .
      .
      </root>

      As always thanks!
        • 1. Re: How to determine size of result object?
          chris.huston.t10 Level 3
          You can get the size by : evt.result.root.offeringRoot.length;

          For your loop you could do something like this:

          for each (var item:Object in evt.result.root.offeringRoot) {
          trace(item.offeringNumber);
          ...
          }

          But it doesn't seem like you need to loop through your result since it is already an XML object and can be bound directly to a variable such as myArray like this:

          var myArray:ArrayCollection = evt.result.root.offeringRoot;

          Vygo