The ActionScript
The following Actionscript is the basic code needed. Hopefully the comments make the code self-explainitory. The next example will include lots of debugging and other features.
import mx.services.*;
/* import all of the webservices class packages.
Note: if you do not use the above import statement you will have to
call the web service with the full path (new mx.services.WebService(..) */
// set it up so that the service is called when the button is pressed.
result_btn.onPress = function() {
// Create a new instance of web service called - stockservice.
var stockservice = new WebService("http://www.flash-db.com/services/ws/companyInfo.wsdl");
// Call the doCompanyInfo method and assign it to the pending call object to handle results.
stockResultObj = stockservice.doCompanyInfo("any","any","macr");
stockservice.onLoad = trace("loading");
// the onResult function is called if the service is successful
stockResultObj.onResult = function(result) {
// example result values. The result is a decoded actionscript object
//version of the xml returned by the operation.
// In this case the result is a object with company, lastPrice etc being properties.
trace("company Name: "+result.company);
trace("lastPrice: "+result.lastPrice);
trace("volume: "+result.volume);
trace("yearHigh: "+result.yearHigh);
trace("yearLow: "+result.yearLow);
}
stockResultObj.onFault = function(fault) {
// If there is any error such as the service not working, the onFault handler will be invoked.
trace(fault.faultCode + "," + fault.faultstring);
}
}
To test, copy the above actionscript and place on the first frame of your movie. Then 'Test Movie'. The output window should display something like:
loading
company Name: MACROMEDIA INC
lastPrice: 26.95
volume: 1676392
yearHigh: 28.80
yearLow: 6.00
So the above code works well and is fairly easy to use, but what about if you need to debug or more closely follow the interactions of a more complicated web service - we'll get to this on the next page.

5 most recent
Flash button as Flex icon
Tree menu
Flash Spell Checker
Flash Remoting Library
MX 2004 Chart/Poll
Articles