- Code: Select all
import alducente.services.WebService;
import flash.events.*;
import flash.net.URLLoader
import flash.net.URLRequest
//find the attached .zip and keep it near your fla file
// Make a button on stage and give it instance name 'btn'
btn.addEventListener(MouseEvent.CLICK, callWS)
function callWS(e:MouseEvent){
passDataToWs('param1Value', 'param2Value', 'param3Value')
}
function passDataToWs( param1, param2, param3){
var ws:WebService = new WebService();
ws.addEventListener(Event.CONNECT, connected);
ws.connect("http://provideWebserviceUrlHere?WSDL");
ws.cacheResults = true;
var initTime:Number;
function connected(evt:Event):void{
initTime = getTimer();
ws.METHOD_NAME(done, param1, param2, param3);
ws.METHOD_NAME(done2)
}
function done(serviceRespone:XML):void{
trace("\nWeb Service Result: ");
var time:Number = getTimer();
trace("Call duration: "+(time - initTime)+" milliseconds");
initTime = time;
}
function done2(serviceRes:XML):void {
ws.clearCache();
trace("\nCache was cleared");
}
}
Take the following steps to resolve the Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation
*If your SWF file location and webservice location both are on different domain then,
Please put and upload the following xml code in a file named 'crossdomain.xml' on the location of where your webservice is hosted.
More Info on CrossDomain.xml
- Code: Select all
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only" />
<allow-access-from domain="WebserviceIsHostedDomain.com" />
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
</cross-domain-policy>
Use FlashFireBug to see the game behind the curtain (requests from flash to webservice).
All The Best...
