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]