R – web service code in actionscript

actionscriptservice

im calling an actionscript class from my main mxml file. the actionscript class is responsible for calling a web service and handling the response, however im having trouble and keep getting the following error; (im new to flex btw)

Error #1009: Cannot access a property or method of a null object reference.

my code goes as follows;

    public function getSites(argWsdl:String):void{
    ws = new WebService();
        ws.loadWSDL(argWsdl);
    ws.getSites.addEventListener(ResultEvent.RESULT,echoResultHandler); 
    ws.getSites();
}

    public function echoResultHandler(event:ResultEvent):void {
        var siteField:ArrayCollection = event.result as ArrayCollection;
        Application.application.setSiteField(siteField);
    }

when i run the debugger the code never reaches the result hanlder and i see the #1009 error in the variable list.

any ideas?

Best Answer

looks like you have it sorted, but just to add more information in case someone else comes along to this question, you generally see this error when you are trying to use something that hasn't been created yet. A lot of the time you will see it when trying to access UI components that have not yet been created (its good to rely on the creationComplete event for these sort of things), but in this case it looks like you are using the webservice before it is completely ready (the wsdl hasnt been loaded yet).

Just so you know, you can also define your webservices in mxml (mx:webservice) and specify the wsdl there or you can also load the wsdl later on from a configuration file afterwards just by referencing the ID.

Related Topic