I just tried out web service in Flex 3. This example is discussed in ActionScript 3.0 Cookbook. Here follows the complete source code.
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” creationComplete=”fnCreationComplete()”>
<mx:Script>
<![CDATA[
import mx.rpc.soap.WebService;
import mx.rpc.soap.LoadEvent;
import mx.rpc.Fault;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
private var webService:WebService;
private function fnCreationComplete():void{
webService = new WebService();
webService.wsdl="http://www.rightactionscript.com/webservices/FlashSurvey.php?wsdl";
webService.addEventListener(LoadEvent.LOAD, onWSDL);
webService.getAverages.addEventListener(ResultEvent.RESULT, onGetAverages);
webService.loadWSDL();
webService.getAverages.addEventListener(FaultEvent.FAULT, onFaultGetAverages);
}
private function onGetAverages(event:ResultEvent):void{
textArea.text = "The averages for Flash and ActionScript are " + event.result.flash + " and " + event.result.actionscript;
}
private function onFaultGetAverages(e:FaultEvent):void{
Alert.show("Fault string"+e.fault.faultString);
}
private function onWSDL(loadEvent:LoadEvent):void{
webService.getAverages();
}
]]>
</mx:Script>
<mx:TextArea id=”textArea” x=”59″ y=”60″ width=”339″ height=”185″/>
</mx:Application>
Before we load the wsdl we are adding a event listener to it. So as soon as the wsdl is loaded the listener function is called and it calls a function getAverages() from web service and it returns two values flash and actionscript which we are displaying in a text field from onGetAverages() a listener function.
humm Flex 3!!!
Good one
Thx,
Tushar