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 following example use's AMFPHP and nusoap to consume two different web services inside of flash. Below is a brief overview, however this application is meant mainly for sample code. A detailed tutorial on using AMFPHP and web services should be available shortly, until then - if you have any questions on this (or on setting up AMFPHP/nusoap) be sure to visit us on the message boards.


The following assumes that you have Flash Remoting up and running, either AMFPHP or other.

If your using AMFPHP and have not installed nusoap yet, you may want to read over - Consuming Web Services with Flash and AMFPHP. In short download the latest version of nusoap and place this in a folder called 'lib' inside the flashservices directory (flashservices/lib). And that's it! Your now ready to consume webservices in flash.

AMFPHP in combination with Nusoap was used in this example, but the same actionscript code and services should work with any remoting software package (coldfusion, .net, etc).

The above example use's the following two web services:
The actual code is included in the download, the most important part of the code is posted below. The following should be enough to get you started using the NetConnection debugger - which will make everything really easy.



Company Info Service

#include "NetServices.as"
#include "NetDebug.as"

// create result handler for quote service.
quoteResult = new Object();
quoteResult.onResult = function(result){
    
// handle quote results
    
company = result.company;
    
// using the netconnection debugger you can see what is returned in your result object,
    // in this case the result object has
    // various properties that correspond to company data. (only one was shown above).
}
quoteResult.onStatus = function(status){
    
_root.Thinking.gotoAndStop(1);
    
_root.status_txt = status.description; //provides good error handling inside flash
}

// sets up the gateway connection.
var serverConn = NetServices.createGatewayConnection("<pathOnServerTo>/flashservices/gateway.php");

// sets up quote service.
var quoteService = serverConn.getService("http://www.flash-db.com/services/ws/companyInfo.wsdl", quoteResult);

// when the lookup quote button is pressed, this function is called.
quote_btn.onPress = function() {
    
// use the wsdl inspector to find the needed parameters (flash-db.com/services/)
    
params = {
        
username:"any",
        
password:"any",
        
ticker: _root.Symbol
    
}
    
// call the quote service.
    // use the wsdl inspector at flash-db.com/services/ for more info on the service.
    
quoteService.doCompanyInfo(params);
}

And that's it. Hopefully enough to play around with.

 Download the Source Files
- be sure to check the message board for help/support.


Note to advanced AMFPHP users: One of the best and easiest ways to combine the error handling of AMFPHP, Nusoap, and the flash NetConnection debugger is by adding the following to the nuSoapImpl function (located in app/Executive.php):

place this after the if/else statment containing $result = $soapclient->call

if ($err = $soapclient->getError()) {
    
trigger_error("error with nusoap, ".$err, E_USER_ERROR);
} else {
    return
$result;
}

// $err is an error string that nusoap sets when ever an error is encountered.

This will return any errors nusoap encounters to the NetConnection debugger. So for example if you enter in an invalid wsdl file, or an invalid method name, you may get something similar to this back:

"Error: error with nusoap, operation BabelFish not present."

Only attempt to add this if you are familiar with AMFPHP.