I have a problem that I cannot seem to easily solve with a call out to a webservice. i have created an actionscript class to act as a webservice handler. In this class i set up my webservice and the corresponding events and declare a property getter to return the arraycollection that holds the resulting table from the .net webservice.this is my class:
public function getWebServiceData(_selectedMortarSize:int, _numStepMaxCharge:int, _piIllum:String, _piUSAmmo:String):void
{
selectedMortarSize = _selectedMortarSize;
numStepMaxCharge = _numStepMaxCharge;
piIllum = _piIllum;
piUSAmmo = _piUSAmmo;
ws = new WebService();
ws.wsdl = "http://lmgis02/cawdapt_ws/cawdapt_dotnet_ws.asmx?wsdl"
ws.getMortarChargeData.resultFormat = "object";
ws.getMortarChargeData.addEventListener("result", myResultHandler); ws.getMortarChargeData.addEventListener("fault", myFaultHandler);
//need to set up a load result handler to catch when the webservice is loaded. From here we will
//pass the parameters and then the results will be returned in the result handler code.
ws.addEventListener(LoadEvent.LOAD, loadHandler);
//call webservice, result event handler will populate the arraycollection which will then be passed to the action script.
ws.loadWSDL();
}
protected function loadHandler(event:LoadEvent):void
{
// send() takes the service parameters
ws.getMortarChargeData.send(selectedMortarSize, numStepMaxCharge, piIllum, piUSAmmo);
}
protected function myResultHandler(event:ResultEvent):void
{
myMortarChargeData = new ArrayCollection();
myMortarChargeData = event.result.Tables.mortarChargeData.Rows;
}
protected function myFaultHandler(event:FaultEvent):void
{
Alert.show(event.toString());
}
i then have a procedure in my widget code that instantiates this class, and (hopefully!) gets the arraycollection and then passes that array collection into another routine that plots a polygon
//Code that calls the webservice handler:
var myWS:MortarsWS = new MortarsWS
myWS.getWebServiceData(selectedMortarSize, numStepMaxCharge.value, piIllum, piUSAmmo);
mortarChargeData = myWS.MortarChargeData;
//code that uses the mortarChargeData
//instantiate FP class with standard trace variables setup
x = new myClass(mortarChargeData, [othervariables])
This is all initiated on a user button click, the parameters i am passing to the webservice are set up by the users interaction with the controls on the widget. The problem I am having is that the loadresult call in the webservice handler is not firing until AFTER the code has dropped into myClass and attempted to use items from the mortarChargeData arraycollection.Why are the webservice loadhandler, the resultant send operation and the result event handler all firing after I intended them to? Can anyone see what I am doing wrong?Hope someone can help!