浏览 2224 次
锁定老帖子 主题:Flex HttpService重用2
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-09-28
package common { import mx.controls.Alert; import mx.rpc.AsyncToken; import mx.rpc.events.FaultEvent; import mx.rpc.http.HTTPService; public class HttpServices { private var http:HTTPService; private var _host:String; private static var https:HttpServices; public function HttpServices() { http = new HTTPService(); } public function set host(value:String):void { _host = value; } public function sendHttpSer(url:String, local:String="/zport/dmd/YDBackScript/asset_handler?callMethod=", json:String="", format:String="e4x", contentType:String="application/x-www-form-urlencoded"):AsyncToken { local = _host + local; http.url = local + url; http.resultFormat = format; http.method = "POST"; http.showBusyCursor = true; http.contentType = contentType; return json.length>0 ? http.send(json) : http.send(); } public function sendJsonService(json:String, url:String="/zport/dmd/Events/evconsole_router", format:String="object"):AsyncToken { return sendHttpSer(url,"",json,format,"application/json; charset=utf-8"); } public static function getInstance():HttpServices { if(!https)https = new HttpServices(); return https; } } } Responder工具类: package common { import mx.controls.Alert; import mx.rpc.AsyncResponder; import mx.rpc.AsyncToken; import mx.rpc.events.FaultEvent; public class ResponserUtils { public function ResponserUtils() { } public static function responderHandler(token:AsyncToken,resultHandler:Function):void { var responder:AsyncResponder = new AsyncResponder( resultHandler, faultHandler ); token.addResponder( responder ); } private static function faultHandler( event:FaultEvent, token:Object=null ):void { // Alert.show("网络服务未能正常访问,请联系管理员解决,:)","错误提示"); trace( "FAULT: " + event.fault.message ); } } } 调用方法: var tokens:AsyncToken = https.sendHttpSer("getAssetsClassReferenceByAssetID&classID="+classID+"&layer="+1); ResponserUtils.responderHandler(tokens,getAssetsRelationship); 回调函数: private function getAssetsRelationship(e:ResultEvent,token:Object=null):void { } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |