views:

2733

answers:

2

i have a function which retrieves values from a webservice , then loops through the returned values and for each returned value does another webservice lookup.

Im having a problem however that when i make the second webservice call within the for loop that the function does not wait for the reuslt and just keeps processing and in turn giving me no value

the code looks like this;

    private function getResult(e:ResultEvent):void{

   var lengthOfResult:int = e.result.length;
   var arrayCollResults:ArrayCollection = new ArrayCollection();
   var resultArray:Array = new Array(e.result);

       for(var i:int = 0 ; i < lengthOfResult; i++){
      var currentName:String = e.result[i].toString();
      arrayCollResults.addItem(e.result[i] + ws.getMatches(currentName)); 
   }

   acu.dataProvider = arrayCollResults;
   }

what can i do to insure that the value of ws.getMatches(currentName) actually returns a value before moving to next line?

A: 

As far as I know flex/as3 cannot do a blocking wait for the result - you have to add a listener and wait to be notified.

Simon Groenewolt
A: 

The documentation here indicates that you do not call the Web service directly, you need to set up an event listener and handle the response on completed delivery.

From the section "Calling web services in ActionScript":

<?xml version="1.0"?>
<!-- fds\rpc\WebServiceInAS.mxml --> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
    <mx:Script>
        <![CDATA[
        import mx.rpc.soap.WebService;
        import mx.rpc.events.ResultEvent;
        import mx.rpc.events.FaultEvent;
        private var ws:WebService;
        public function useWebService(intArg:int, strArg:String):void {
            ws = new WebService();
            ws.destination = "echoArgService";
            ws.echoArgs.addEventListener("result", echoResultHandler);
            ws.addEventListener("fault", faultHandler);
            ws.loadWSDL();
            ws.echoArgs(intArg, strArg);
        }

        public function echoResultHandler(event:ResultEvent):void {
            var retStr:String = event.result.echoStr;
            var retInt:int = event.result.echoInt;
         //Do something.
        }

        public function faultHandler(event:FaultEvent):void {
      //deal with event.fault.faultString, etc
        }
        ]]>
    </mx:Script>
</mx:Application>

Put the "arrayCollResults.addItem(...)" segment in the result handler for your ws.getMatches() event.

seanhodges