public class Http
{
private static var _requests:Array = [];
private static function getRequest():HttpRequest
{
return _requests.length? _requests.shift() : new HttpRequest();
}
private static function onRequestError(e:*):void
{
trace(e);
}
private static function onRequestComplete(hr:HttpRequest, call:Handler):void
{
trace(hr.data);
call.runWith(hr.data);
_requests.push(hr);
}
private static function send(path:String,call:Handler,type:String):void
{
var hr:HttpRequest = getRequest();
hr.once(Event.COMPLETE, Http, onRequestComplete,[hr,call]);
hr.once(Event.ERROR, Http, onRequestError);
hr.send(path, null, type, 'text');
}
public static function get(path:String,call:Handler):void
{
send(path, call, "get");
}
// 未完待续
}
如果疑问,可加QQ:29727880