您不能进行同步呼叫,但可以等到服务器回复后再发送另一个请求。
但是,如果你真的要在一个循环中向一个web服务器发送上千个请求,那么可能存在设计缺陷?
// small example to see how do the chaining call
class A extends EventDispatcher {
private var urlLoader:URLLoader;
private var urlRequest:URLRequest;
private var sendCount:int=0;
//......
public function init(url:String):void{
urlLoader=new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, sendData);
urlRequest = new URLRequest();
request.url = url;
request.method = URLRequestMethod.POST;
count=1000;
}
//....
private var data:Object;
//.....
//
function sendData(e:Event=null):void{
if (count-- > 0) {
urlRequest.data = data; // put the data based on the counter
urlLoader.load(urlRequest);
} else {
urlLoader.removeEventListener(Event.COMPLETE, sendData);
dispatchEvent(new Event(Event.COMPLETE));
}
}
}
var a:A=new A();
a.addEventListener(Event.COMPLETE, function():void{
trace("send finished");
}); // listen to the event complete so
// you know when you send is finished
a.init("http://...."); // ok init your send
a.sendData(); // and start the send that will be chain each time the webserver answer