Consuming Outside Web Services


So far, the only web services we have worked with are the ones we built ourselves. That's not the idea behind web services. The idea is that anyone can build them, and anyone can use them as long as they know how to work with them.

There are a couple of great sites on the web that store references to web services for people to work with:

http://www.webservicex.net/WS/default.aspx

http://www.xmethods.com/

The one we will be using can be found at

http://www.aspxpressway.com/maincontent/webservices/piglatin.asmx

This web service will translate a string of text we send it to pig Latin and return it.

For those not familiar with pig Latin, it's a language that moves the first letter from the front of certain words to the end and then adds an "ay" to it.

So if you have a sentence just like this, it would read like this:

So if you avehay a entencesay ustjay ikelay isthay, it ouldway eadray ikelay isthay.

The following example will build an application to do just that. But before you jump in to the example, add the WSDL to the Web Services panel (http://www.aspxpressway.com/maincontent/webservices/piglatin.asmx?WSDL).

1.

Create a new Flash document.

2.

Drag the TextArea component onto the stage, give it an instance name of text_ta, and change its dimensions to 250x130.

3.

Drag an instance of the Button component onto the stage under the TextArea component; give it an instance name of TRanslate_butn, and change its label parameter to Translate.

4.

Then drag an instance of the WebServiceConnector component onto the stage and give it an instance name of myConnector.

5.

With the WebServiceConnector component selected, open the Component Inspector to the Bindings tab and click the Add Binding button. Select the textToTranslate:String option and click OK. Then bind it to the TextArea component. Add another binding and this time select the results:String, click OK, and bind that to the TextArea component as well. (This will make it so the text being translated will come from and be returned to the TextArea component.)

6.

Create a new layer called actions.

7.

In the first frame of the Actions layer, open the Actions panel and place this code in it:

 //create the listener object var tranObj:Object = new Object(); //the event tranObj.click = function(){     myConnector.trigger(); } //add the event listener to the Button component translate_butn.addEventListener("click", tranObj); 

Now test the movie, place this paragraph in (or one of your own), and click the Translate button. When the results are returned, you should see something like Figure 25.11.

Figure 25.11. Using external web services with Flash is fun and easy with the WebServiceConnector and Data Binding.


Now that you have seen how to absorb web services created by other people, you might want to start working on some of the major web services on the web, such as the Google.com web service found at

http://www.google.com/apis/

Or you might want to experiment with the web service API of the mother of all web appsAmazon.




Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net