# Loop is faster than Web Services results!

**URL:** https://forum.kirupa.com/t/loop-is-faster-than-web-services-results/251926
**Category:** Uncategorized
**Created:** [February 13, 2008, 11:57pm UTC](https://forum.kirupa.com/t/loop-is-faster-than-web-services-results/251926 "2008-02-13T23:57:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Miguelele](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@Miguelele](https://forum.kirupa.com/u/Miguelele)
#### Post date: [February 13, 2008, 11:57pm UTC](https://forum.kirupa.com/t/loop-is-faster-than-web-services-results/251926/1 "2008-02-13T23:57:17Z")

</div>

Help!! I have a loop that iterates an array from XML, checking each element against a Web Service.  
As the response from the Web Service needs some time, the loop keeps on running, so when I get the first response from the server, and I try to associate it to the array item, the loop is already in the last item!!!, and I cant use the index as a reference!!

Please, how must I manage it?

Regards: Miguel  
[AS]  
private function display ():void  
{  
for (var $counter:int = 0; $counter\<items.entry.length(); $counter++)  
{  
// I start the Web Service  
startWebService();  
}  
}

private function startWebService():void  
{  
webService = new WebService();  
webService.wsdl = $webServiceUrl;  
webService.loadWSDL();

```
    // Now I wait the WSDL to be loaded
webService.addEventListener(LoadEvent.LOAD, checkItem);
    // BUT........ the loop keeps on running!!!!!!!!!

```

}

private function checkItem(e:LoadEvent):void  
{  
// I add the listeners to be activated when a resonse comes from the Web Service  
webService.WS\_CheckItem.addEventListener(ResultEvent.RESULT, displayItem);  
webService.WS\_CheckItem.addEventListener(FaultEvent.FAULT, onError);

```
    // Now I check data from this array element with the Web Service
    // BUT......... as the loop keeps on running,
        // the $counter is already in the last iteration,
        // so I always get data from the last element!!!!
webService.WS_CheckItem(items.entry[$counter].dataToCheck);

```

}

private function displayItem(e:ResultEvent):void  
{  
// Should show the results form the item depending on the result  
}  
[/AS]
