var _loader:URLloader;
_loader = new URLLoader();
//建立事件的侦听
configureListeners(_loader);
//建立urlloader的数据
var loaderData:URLVariables = new URLVariables();
loaderData.userName = "kidliu";
loaderData.passWord = "123456";
//建立请求地址
var url:String = "localhost/login.php";
var request:URLRequest = new URLRequest(url);
//把数据和请求邦定
request.data = loaderData;
//设定请求的方式
request.method = URLRequestMethod.POST;
try {
_loader.load(request);
} catch (error:Error) {
trace(error);
}
private function configureListeners(dispatcher:IEventDispatcher):void {
//加载完成事件;
dispatcher.addEventListener(Event.COMPLETE, loaderHandler);
//开始访问事件;
dispatcher.addEventListener(Event.OPEN, loaderHandler);
//加载进度事件;
dispatcher.addEventListener(ProgressEvent.PROGRESS, loaderHandler);
//跨域访问安全策略事件;
dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loaderHandler);
//Http状态事件;
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, loaderHandler);
//访问出错事件;
dispatcher.addEventListener(IOErrorEvent.IO_ERROR, loaderHandler);
}
private function loaderHandler(event:*):void
{
switch(event.type) {
case Event.COMPLETE:
trace("成功: " + _loader.data);
break;
case Event.OPEN:
trace("open: " + event);
break;
case ProgressEvent.PROGRESS:
trace("progress: " + event);
break;
case SecurityErrorEvent.SECURITY_ERROR:
trace("securityError: " + event);
break;
case HTTPStatusEvent.HTTP_STATUS:
trace("httpStatus: " + event);
break;
case IOErrorEvent.IO_ERROR:
trace("ioError: " + event);
break;
}
}