I need to call a method inside web service and passing to it it's parameters from action script 3.0 can anyone help me plz? i searched all over the internet and found solutions with flex and i am not working with flex i am working with action script 3.0
3 Answers
I use something like this:
var request:URLRequest = new URLRequest();
request.url = 'http://example.org';
// If you're POSTing data:
request.method = URLRequestMethod.POST;
request.data = new URLVariables({ /* Your object */ });
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES; // If you're using POST
try {
loader.load(request);
} catch(error:Error) {
// Handle error
}
trace(loader.data); // Result
Documentation:

- 14,394
- 6
- 41
- 36
-
Mr.Ron i mentioned in my question that i need to call a method inside a web service not to request file or page. The code that u wrote is suitable for requesting Asp page but in the web service the issue differ and we need to use SOAP and encapsulate data inside it Read the questionfirst before ans – Ahmy Apr 08 '09 at 15:44
-
Ahmy, I read your question, but you didn't specify a SOAP-based web service. There are multiple types of web services; my answer is catered toward RESTful services because have been popular recently. – Ron DeVera Apr 08 '09 at 21:32
-
If it's a .Net service, you can easily enable POST and GET calls beside the default SOAP. It's built in, just a setting that needs to flipped. – Jacob Poul Richardt Apr 10 '09 at 12:31
Here is the code that I used in one of my Flex projects...
import mx.rpc.soap.WebService;
public var service:WebService = new WebService();
override protected function initializationComplete():void
{
service.wsdl = "http://localhost:1133/YourService.asmx?wsdl"
// GetPayload is the method name you're calling on your web service
service.GetPayload.resultFormat = "e4x";
service.GetPayload.addEventListener("result", yourResultHandler);
service.GetPayload.addEventListener("fault", yourFaultHandler);
// Method to call once the WSDL is loaded
service.addventListener(LoadEvent.LOAD, loadHandler);
service.loadWSDL();
}
Then here is what happens once the WSDL is loaded
protected function loadHandler(event:LoadEvent):void
{
// send() takes the service parameters
service.GetPayload.send("Product");
}
You just need to write the two methods to handle the XML returned by your services (the data is returned in e4x format:
protected function yourResultHandler(event:ResultEvent):void
{
_messageXml = XML(event.result);
}
proteted function yourFaultHandler(event:FaultEvent):void
{
Alert.show(event.toString());
}

- 242,243
- 40
- 408
- 536
-
I am not using Flex, i mentioned in my question that i need solution for calling method inside web servie in Action Script 3.0 – Ahmy Apr 12 '09 at 09:27
-
You don't need to be using Flex to use the mx.rpc.soap.WebServices namespace. – Justin Niessner Apr 13 '09 at 01:32
-
when i import it in Action Script 3.0 it reports to me: 1172: Definition mx.rpc.soap:WebService could not be found. ??????????????????????????? – Ahmy Apr 13 '09 at 08:17
-
Hmmm...is it possible for you to just download the Flex SDK from http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3 You can then include the src folder from the SDK to your Flash Classpath. – Justin Niessner Apr 13 '09 at 12:51
you can use the web services by one of the tricky method first you make swf by compiled in flex environment which includes the import statements of webservice like import mx.rpc.webservices. now compile it you will get a swf. now you go to as3.0 and make a empty movieclip on stage and in linkage property put it import for runtime sharing and put the a.swf(ex)on textbox in sharing.now you can import the statement in your action script file import mx.rpc.webservices.and use the method same as flex. definately u will be able to access web services....