views:

1746

answers:

1

Hello,

I'm new at flash and I'm trying to access a .net web method I've created from Flash CS3, using AS2. The problem is I cannot make this work.

The code is the following:

`import mx.services.*;

var myXml:XML = new XML();

var ws1:WebService = new WebService("http://localhost/manyworlds/mwframework/webservices/statisticscharts.asmx?wsdl");

ws1.onLoad = function(wsdl:Object){ trace("Load"); //Web method that retrieves a XML. myXml = ws1.GetTopicsForStatistics(); myXml.load(); };`

Thanks,

Brian

+1  A: 

Here's an example with code that I've used in the past:

var myXml:XML = new XML();

public var service:WebService = new WebService();

service.wsdl = "http://pathToYourWsdl";
service.SomeWebMethod.resultFormat = "e4x";
service.SomeWebMethod.addEventListener("result", resultHandler);
service.SomeWebMethod.addEventListener("fault", faultHandler);
service.addEventListener(LoadEvent.LOAD, serviceLoadHandler);

service.loadWSDL();

protected function serviceLoadHandler(event:LoadEvent):void
{
    service.SomeWebMethod.send();
}

protected function resultHandler(event:ResultEvent):void
{
    myXML = XML(event.result);
}

protected function faultHandler(event:FaultEvent):void
{
    // Handle a service fault here.
}

This code handles all service calls Asynchronously and then assigns the result of your method call to the XML variable. It's pretty self explanitory. "SomeWebMethod" would be the name of the Web Method in your service to call. If it needs parameters, they get added like so:

service.SomeWebMethod.send(param1, param2, ...);
Justin Niessner
Justin,Thanks for your quick answer.I still can't make this work though. I don't know if that works only for flex or also for flash cs3, because when I add the required import for the soap web service(import mx.rpc.soap.WebService) I get an error saying this class couldn't be loaded.Any thoughts?Thanks for your help.Brian
Brian Roisentul
You might have to download the Flex 2 SDK and add the WebService classes to your Flash Classpath settings.
Justin Niessner