hide side navigation
    5 most recent
    Web Services
  Flash Spell Checker  Company information and news  LinkToMe  Flash Google MX  Flash Currency Conversion  Language Translation  Flash Server Inspector  Stock Quotes in Flash  Flash 2D and 3D charts
    Library's
    Component's
    Applications
    Articles
The Flash 6 (MX) Player is required to view this area.
Please read over the below text - before downloading the app at the bottom.


Flash Currency Conversion Service
This application is an example of using Flash MX to communicate with a with a Web Service. By using a combination of the Load Vars Object, Flash MX Components, and a PHP Soap Toolkit - we can easily build applications such as these.

Web Service's Part II
This is Flash-db's 2nd publically available example of using a Web Service with Soap in Flash. The first one was the Babelfish Translator - which you can get to by clicking here.. Over the next couple weeks we will have many more flash clients for web service's available. With each new example we will put up increasing complex flash client's. These first 2 should give you a good insight to what is needed and how to do it. Please leave either a Flash-db logo or a text link on the convertor if you decide to use it on a non-testing commercial site.

About
The web service that we are using provides us with the currency exchange rate between any two countries. What we are doing on the flash side is selecting two countries, country A and country B, entering an amount to convert - then sending those 3 values to a script. The script then looks up the current exchange rate between country A and country B and returns the value. We then multiply that value times the amount entered by the user to get the actual amount of Country B dollars for every dollar of Country A. This may sound a bit confusing - but is really only multiplying 2 values. By looking over the 'conversion.php' script, hopefully this becomes a bit more clear.

To Use:
The first thing you will need to do is look over the included fla file and read the comments and code. The newest concept to most of us will be using the Load Vars object to send and Load data. The Load Vars Object is not all that different from LoadVariables, this is realized when thinking of Movie Clips as Objects (which they are) and combining that more closely with a method to send and load data. If you where used to the Flash 5 XML object - you'll be right at home. One of the greatest things about the Load Vars object is that it makes working and thinking in terms of Objects instead of movie clips much more intuitive and clear.

To send and recieve Soap based Objects - you will need to use one of the PHP Soap toolkits. We are going to use NuSoap for this example. We are using NuSoap because of it's ease of use, only 1 file, and can be installed on any server/platform at no cost. This is great because we can build and consume Web services with no reliance on propritory software or restrictive licensing agreements. Basically NuSoap is a set of PHP class's that handles everything for you. To use this - we need to specify a couple of items in the client script, including the parameters to be sent, path to WSDL file, and the method to use. This is done in about 5 lines. And is shown below:

The version of Nusoap we are using was choosen because of it's ease of use. The newer version's of Nusoap and the PEAR PHP soap toolkit are more powerful and feature rich solutions - however they require a bit more thought when using.

// Include Nusoap.php file
require_once('nusoap.php');

// Define needed parameters and put them in an array.
$parameters = array(
	'country1' 		=> $currValue1, 
	'country2' 		=> $currValue2
);	

// Define new object and specify location of wsdl file.
$soapclient 		= new soapclient('Currency.wsdl','wsdl');

// call the method and get the result.
$result 			= $soapclient->call('getRate',$parameters);

// Lets do some math, multiplies entered amount by the current conversion rate (result).
$convertedAmount 	= ($amount * $result);

// Print out a nice formatted return string and send it back to flash...
print "&soapOut=$convertedAmount&";
Important Parts
Currency.wsdl - the wsdl file, containing a description of the service and where to access it. Once you've looked over enough of these you'll start to get a feel for them. But it might be a good idea to do some reading on this topic. (IBM tutorial on WSDL - Part II of that) (their's a lot more going on here - but fortunatly PHP takes care of all the details). For this example - all we have to know is the path to the file, which in this case is assumed to be in the same directory. In most case's you do not need to use a WSDL file, but they are helpful.

getRate - the method to invoke. These usually have similiar names, most published service's will provide you with this name. By reading over the wsdl file you can find them manually if necessary.

So when first testing this out - Add the NuSoap.php, the Translate.php (client code), the SWF file (flash client), and the WSDL file - to a directory on your server. And that's about it. As stated above - this is a simple example and it's basically up here to help us all get going and start building more and more complex Flash clients for web services. In the future we will have some info on this site on how to build your own webservice. And some more examples of consuming increasingly complex services. I can see some of the greatest potential for Flash in this area - hope you can to.

In case's of accessing more complex soap based services - the result is usually sent back as a more complex object (array). In that case we would have to add a couple of lines to format the array as necessary, needed, or wanted.

Important: Nusoap, where to get nusoap.php file
- The 'nusoap.php' file has to be distributed with the rest of the contents of the authors zip file, because of the license agreement included with Nusoap. So you can either unzip the 'Nusoap-0.6.1.zip file' (included in this download) and extract that file. Or vist:
http://dietrich.ganx4.com/nusoap/
Just download it - Unzip it and extract the file called 'NuSoap.php'. And use that in conjunction with the Translate.php file and SWF client.

You can also check out the newest CVS version of Nusoap on sourceforge at: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/nusoap/lib/ (although when first starting it will be much easier to simply use the 1 nusoap.php file).

About NuSoap:
NuSOAP is a rewrite of SOAPx4, provided by NuSphere. NuSOAP is a group of PHP classes that allow developers to create and consume SOAP web services. It does not require any special PHP extensions, which makes it usable by all PHP developers, regardless of ISP, server or platform.

Nusoap proves development of PHP web services as an alternative to .net and J2EE. (as if we needed any convincing!!)..

If you are interested in a version of this Soap toolkit that has some extra functionality I would recommend:
http://pear.php.net/package-info.php?pacid=87

The PEAR Soap Toolkit - may be a bit harder to use at first (which is the reason I'm using Nusoap for this example) but you will find some added features - that and it's updated much much more often.

Extra big Thanks to:
*** Dietrich Ayala *** - For NuSoap (which is also the base for part of the Pear/CVS version)!!!
*** Shane Caraveo *** For working on the PEAR and CVS versions of SOAP for PHP!!!!

Download Example Files Click here

Please keep a logo or text link back to Flash-db on the Flash client (for commercial and non-testing implementations

If you have any trouble with the Flash or PHP side - be sure to visit the message boards at Flash-db Message Boards. Some of the functions for changing the style's of components and change handlers may be a bit confusing on the Flash side of things.

Flash Client Author: Jeff Hill