First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Jeffrey F. Hill | Website: http://www.flash-db.com/services/

The Server Side

Flash can't load data from an outside domain. This being the case we need to use some type of script that acts as a proxy and also handles all of the details of sending and receiving soap based messages. We have quite a few options available to use for this step. Their are literally hundreds of different Soap toolkits that can handle this part for us. The most relevant ones would be the MS .net soap toolkit from Microsoft, Flash Remoting which requires Coldfusion or a special component (Salsa) installed on your server, and of course either of the PHP soap toolkits. A soap toolkit is basically a couple of classes and functions that handles all of the details of sending and receiving soap based messages. So what did we choose for this tutorial, well of course one of the PHP toolkits.

Nusoap/SOAPx4: In this example we are going to use Nusoap (aka SOAPx4). We are using Nusoap because it only requires 1 php file to be placed anywhere on any server. This also allows us to use web services with any computer running PHP. By any I mean any - You can build your application on any windows, Mac, Linux desktop and deploy it on any Windows, Mac, Unix, Linux Server. So it's tough to beat a setup that only requires 1 file on any server. Their are no special installation or server setup worries, their is nothing to buy, and you can build your own Soap based web service just as easily as sending a soap message. The main disadvantage of Nusoap is that at the time of this writing it is not as mature as some of the other toolkits (.Net) and has some growing to do. But it works for any web service and great for the example so we'll let it go at that. So here goes:

First: You will need to place the Flash Client we just created, a file called 'nusoap.php' (in the download), and the following code in the same directory on your server. In the future you can change around the paths - as only 1 nusoap.php file is needed for all clients. Also you might want to experiment with setting it up so that the path to WSDL file and operation/method to be used - is sent from the flash movie instead of being specified in the script, this creates a more generic soap client - but generic solutions can also cause problems and are limiting).

< ?
$Mode 		= $HTTP_POST_VARS[Mode];
$sourceData 	= $HTTP_POST_VARS[sourceData];  

// Include the NuSoap Class's.

// Add necessary Parameters.
$parameters = array(
		"translationmode"	=>$Mode,
	 	"sourcedata" 	=>$sourceData

// Create a new object
$soapclient 	= new soapclient('http://www.xmethods.net/sd/2001/BabelFishService.wsdl','wsdl');

// Call the service.
$result 		= $soapclient->call('BabelFish',$parameters);

// Print the result.
print "&soapOut=$result&";

? >

The first 2 lines are needed to indicate the variables coming into the script from flash via 'POST'. The next line includes the Nusoap Soap toolkit classes needed for the details. Then we specify the input parameters, in this case translation mode and sourcedata are required. Then we need to create a new soap Client. In this example we specify the path to the WSDL file (Web Service description language), the WSDL file describes the service that we are going to use - and indicates all of the important parts in an XML format. The WSDL file is parsed by the toolkit and used to call the service (among other things). Usually a Service has a couple of available operations or methods in which you can use - these are also specified in the WSDL file. In this case we are using the 'BabelFish' operation/method. When we call this script - that operation (basically a function on some other server) is invoked and a result is returned. The variable $result holds the result and is passed back to flash on the last line. This is a simple case - in most case's the $result will hold an array or other more complex structure's (like with Google's API) - that needs to be parsed before it's sent back. Usually it's only 1 or 2 additional lines though.

Well this tutorial is not on WSDL so I'll spare the details - but usually the most important part of the WSDL file is the location of the EndPoint - the Endpoint is where the service actually/physically resides. In the above script you can skip the middle WSDL file and indicate the exact endpoint if wanted.

To visually see the WSDL file - you can use the following Tool, which is a Flash application that Parse's a WSDL file and describes everything in that file in an easy to read/use Flash interface - the link to that for the BabelFish service is as follows:


Well that's about it. We'll finish up with some links to additional resources and a few closing words.

» Level Advanced

Added: 2002-08-19
Rating: 7 Votes: 10
(10 being the highest)
» Author
Jeffrey Hill is a freelance web developer from Boulder, Colorado. He specializes in creating and developing dynamic database driven Flash content, applications, and content management systems. Specialty's include SQL, PHP, Perl, XML, web services, and Flash clients for web services.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.