How do I loop through result objects in Flex?

I am having troubles by hand knotting via xml information that is obtained using an HTTPService call, the xml looks something similar to this:


When the webservice outcome occasion is discharged I do something similar to this:

for(var i:int=0;i&lt;event.result.DataTable.Row.length;i++)
    if(event.result.DataTable.Row[i].text == "foo")'foo found!');

This code functions after that there is greater than 1 "Row" nodes returned. Nonetheless, it appears that if there is just one "Row" node after that the event.DataTable.Row object is not a mistake and also the code ultimately damages.

What is the correct means to loop via the HTTPService result object? Do I require to transform it to some sort of XMLList collection or an ArrayCollection ? I have actually attempted establishing the resultFormat to e4x which has yet to deal with the trouble


2022-06-07 14:37:40
Source Share
Answers: 3

The trouble hinges on this declaration


length is not a building of XMLList, yet a method:


it is complex, yet that is the means it is.

Enhancement: in fact, the most safe point to do is to constantly make use of a for each loop when repeating over XMLLists, in this way you never ever make the blunder, it is much less code, and also less complicated to read:

for each ( var node : XML in event.result.DataTable.Row )
2022-06-07 15:54:01

Row isn't an array unless there are numerous Row components. It is aggravating. You need to do something similar to this, yet I have not created AS3 in a while so I neglect if there is an exists function.

if (exists(event.result.DataTable) && exists(event.result.DataTable.Row)){
  if (exists(event.result.DataTable.Row.length)) {
    for(var i:int=0;i<event.result.DataTable.Row.length;i++)
        if (exists(event.result.DataTable.Row[i].text)
        && "foo" == event.result.DataTable.Row[i].text)
  'foo found!');
  if (exists(event.result.DataTable.Row.text)
  && "foo" == event.result.DataTable.Row.text)'foo found!');
2022-06-07 15:03:49

I would certainly store it in an Xml object and afterwards utilize its approaches to look for the node value you require.

var returnedXml:Xml = new Xml(event.result.toString());
2022-06-07 15:03:31