3 Replies Latest reply on Jul 26, 2007 8:12 AM by YevgenK

    WebService WAIT

    texas_stingray
      I am calling an WebService via the send(). I need to next line of the ActionScript not to execute until the WebServer returns as it uses the results for additional processing.

      Thanks
      Scott
        • 1. Re: WebService WAIT
          rotoole
          you could put the rest of that function in another function that then gets called on the return of that webservice or dispatch an event or something of that nature. at first i was thinking if you use var:* = httpservice.send() or something like that you could do in actionscript 2 but i'm not too sure if that still works in 3. hope that helps
          • 2. Re: WebService WAIT
            ntsiii Level 3
            Scott, you cn NOT do that, period. Data calls are asynchronous. You MUST do as Rob suggests and use the result event to invoke your processing.

            No, Rob, you can not do: var:* = httpservice.send(.. to get the result data. Not in as2 either.

            Here are some code snippets below.
            Tracy

            Sample code using HTTPService, e4x, handler function to populate a list item.
            Also shows usage of AsyncToken.

            The DataGrid tag:
            <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>


            The HTTPService tag:
            <mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" fault="..../>

            Script block declaration:
            import mx.rpc.Events.ResultEvent;
            [Bindable]private var _xlcMyListData:XMLListCollection;

            Invoke send:
            var oRequest:Object = new Object();
            oRequest.Arg1 = "value1";
            var callToken:AsyncToken = service.send(oRequest);
            token.callId = "myQuery1";

            Result Handler function:
            private function onResult(oEvent:ResultEvent):void {
            var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
            var xlMyListData:XMLList = xmlResult.myListData; //depends on xml format, is row data
            _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a collection
            trace(_xlcMyListData.toXMLString()); //so you can see exactly how to specify dataField or build labelFunction
            var callToken:AsyncToken = oEvent.token;
            var sCallId = callToken.callId; //"myQuery1"
            switch(sCallId) {
            case "myQuery1":
            doQuery2();
            break;
            ...
            }
            }//onResult
            • 3. Re: WebService WAIT
              YevgenK
              My sample code will help to solve your problem:
              1.
              <mx:HTTPService id="loginRequest" url="login.php" method="POST" useProxy="false" result="loginHandler(event)" />
              2.
              private function send_login(event:Event):void {
              var myobj:Object = new Object();
              myobj.user = pop1.Formuser.text;
              myobj.password = pop1.Formpassword.text;
              loginRequest.send(myobj);

              }
              private function loginHandler(event:ResultEvent):void{
              var msg:String = event.result.logins.login.text;
              }