Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems passing functions in flex / actionscript 3
    text
    copied!<p>I'm new to flex and I am building a wrapper class for the WebService object to make my main code mxml cleaner. I am trying to pass a function to a class method to set as the result event handler for the soap call and it is not working as expected.</p> <p>Here is the class:</p> <pre><code>package { import mx.rpc.events.ResultEvent; import mx.rpc.soap.WebService; public class WebServiceObject { private var wsdl:String = "http://localhost:8080/WebApplication1/TestWs?wsdl"; private var testWs:WebService; public function WebServiceObject() { try { testWs = new WebService(wsdl); testWs.loadWSDL(); } catch(errObject:Error) { trace(errObject.toString()); } } public function getSomething(resultHandler:Function):void { testWs.getSomething.addEventListener(ResultEvent.RESULT, resultHandler); testWs.getSomething.send(); } } } </code></pre> <p>This is the mxml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"&gt; &lt;mx:Script&gt; &lt;![CDATA[ import WebServiceObject; import mx.rpc.events.ResultEvent; import mx.controls.Alert; private function test():void { var test:WebServiceObject = new WebServiceObject(); test.getSomething(handler); } public function handler(event:ResultEvent):void { trace(event.result); } ]]&gt; &lt;/mx:Script&gt; &lt;mx:Button label="Test" click="test();"/&gt; &lt;/mx:Application&gt; </code></pre> <p>The web service call is started and the call goes out but the result does not get passed back to the event listener. I tried using a class method as the handler and got the same result. All the pieces work if they are in the mxml code tag.</p> <p>Is this doable? Am I missing something?</p> <p>Thanks.</p> <p>EDIT:</p> <p>OK apparently (this didn't work):</p> <pre><code>testWs = new WebService(wsdl); testWs.loadWSDL(); </code></pre> <p>is not the same as (this did work, note where the wsdl URL is passed in):</p> <pre><code>testWs = new WebService(); testWs.loadWSDL(wsdl); </code></pre> <p>and I was quite sure that I tried it both ways... anyway problem solved.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload