views:

1445

answers:

3

hi,

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?

A: 

sorted it out,

i needed to created a loadEvent and loadhandler. Once loadWsdl is called the loadhandler specifies the laodHandler to use, inside the loadHandler i call the method name as seen in the wsdl

combi001
A: 

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.

Ryan Guill
A: 

thanks Ryan,

the main reason im using a seperate actionscript class is so i can reuse the same web service calls across my components without having to retype the same code. I couldnt think of a better way to do this - maybe a could have done the same with a custom component

combi001
no, that sounds like a fine way of doing it. Just like you have already noticed, make sure you check and make sure everything is created and ready to go before you issue a call and things like that. you also might want to load your wsdl in the constructor of the separate class.
Ryan Guill