[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Wait for webservice response before returning value

Posted on 2006-05-15
5
Medium Priority
?
297 Views
Last Modified: 2008-02-01
I have a function that is getting some data from a webservice.
I would like to return the data, but the webservice has not responded when the 'return' statement is fired.

How do I wait for the webservice response???

========================================

function IDLabel(myString1:String):String {
      var stockservice = new WebService("http://localhost/...../mywebservice.asmx?WSDL", stockServiceLog);
      stockservice.onLoad = function(wsdlDocument)
      {
            var pending:PendingCall = this.IDLabel(myString1, myString2);
            pending.onResult = function(result)
            {
                  if(typeof result.diffgram == "string"){
                        var p = new XML(result.diffgram);
                  } else {
                        var p = new XML(result.diffgram);
                  }
                  p.ignoreWhite = true;
                  _root.LokationID = p.firstChild.firstChild.firstChild.firstChild.firstChild;
                  //I tried placing the return statement here - but that doesn't work
      
           }
           stockResultObj.onFault = function(fault)
           {
                trace(fault.faultCode + "," + fault.faultstring);
           }
             
      }

      return _root.LokationID;
}
0
Comment
Question by:sotea
3 Comments
 
LVL 19

Expert Comment

by:Montoya
ID: 16682403
You're looking for onData, I presume, when reading your web service info, which comes in in XML

onData (XML.onData handler)

onData = function(src:String) {}

Invoked when XML text has been completely downloaded from the server, or when an error occurs downloading XML text from a server. This handler is invoked before the XML is parsed, and you can use it to call a custom parsing routine instead of using the Flash XML parser. The src parameter is a string that contains XML text downloaded from the server, unless an error occurs during the download, in which case the src parameter is undefined.

It's actually pretty easy to use and if you pull up the help for onData you will see a simple example there: Looks like this...

XML.prototype.onData = function (src:String) {
    if (src == undefined) {
        this.onLoad(false);
    } else {
        this.parseXML(src);
        this.loaded = true;
        this.onLoad(true);
    }
}

0
 
LVL 1

Author Comment

by:sotea
ID: 16690656
Hi Iammontoya,

Thanks for the info - but I can't figure out how to implement it into my webservice call.

Could you show me, using the code I provided in my question...
0
 
LVL 1

Accepted Solution

by:
MartiniMon earned 2000 total points
ID: 16701870
This works with other services so you might try the following:

Replace:
 pending.onResult = ***

With this to call your function like so:

pc.responder = new RelayResponder(this, "myFlashFunction");

function myFlashFunction(rs:ResultEvent):Void {
 if(typeof rs.result.diffgram == "string"){
                    var p = new XML(rs.result.diffgram);
               } else {
                    var p = new XML(rs.result.diffgram);
               }
               p.ignoreWhite = true;
               _root.LokationID = p.firstChild.firstChild.firstChild.firstChild.firstChild;
               //I tried placing the return statement here - but that doesn't work

}

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to record live broadcast.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question