美文网首页程序员
LayaBox Http请求封装管理

LayaBox Http请求封装管理

作者: 3c9a4f007e1b | 来源:发表于2018-08-03 11:36 被阅读15次
    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

    相关文章

      网友评论

        本文标题:LayaBox Http请求封装管理

        本文链接:https://www.haomeiwen.com/subject/qmjyvftx.html