_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);