farm通信协议的分析

来源:互联网 发布:苹果手机怎么清除游戏数据 编辑:程序博客网 时间:2024/06/02 20:48
package com.qzone.qfa.core {
    import com.qzone.qfa.events.*;
    import flash.events.*;
命令类扩展自事件分发类,实现命令接口
    public class Command extends EventDispatcher implements ICommand {

        private var _body;
        protected var _running:Boolean;

        public function Command(){
            this.init();
        }
        public function get body(){
            return (this._body);
        }
        public function set body(_arg1):void{
            this._body = _arg1;
        }
        public function get running():Boolean{
            return (this._running);
        }
        public function execute(_arg1=null):void{
            this._running = true;
            this.finish();
        }
        public function init():void{

        }

命令完成后发出CommandEvent,该事件中有结果及命令体

        protected function finish(_arg1=null):void{
            this._running = false;
            var _local2:CommandEvent = new CommandEvent(CommandEvent.COMPLETE);
            if (_arg1){
                _local2.result = _arg1;
            };
            if (this._body != null){
                _local2.body = this._body;
            };
            dispatchEvent(_local2);
        }
        protected function error(_arg1=null):void{
            this._running = false;
            var _local2:CommandEvent = new CommandEvent(CommandEvent.ERROR);
            if (_arg1){
                _local2.result = _arg1;
            };
            if (this._body != null){
                _local2.body = this._body;
            };
            dispatchEvent(_local2);
        }
        public function destroy():void{
            this._running = false;
        }

    }

}//package com.qzone.qfa.core

public class CommandEvent extends Event {

        public static const REQUEST:String = "RequestCommand";
        public static const COMPLETE:String = "CommandComplete";
        public static const ERROR:String = "CommandError";

        public var command:Class;
        public var body;
        public var dataBindStr:String;
        public var dataBindCall:Function;
        public var completeHandler:Function;
        public var errorHandler:Function;
        public var result;

        public function CommandEvent(_arg1:String, _arg2:Class=null, _arg3=null, _arg4:String="", _arg5:Function=null, _arg6:Function=null, _arg7:Function=null, _arg8:Boolean=false, _arg9:Boolean=false){
            this.command = _arg2;
            this.body = _arg3;
            this.dataBindStr = _arg4;
            this.dataBindCall = _arg5;
            this.completeHandler = _arg6;
            this.errorHandler = _arg7;
            super(_arg1, _arg8, _arg9);
        }
    }

public class CommandManager {

        private static var _instance:CommandManager;

        private var _listeners:Dictionary;

        public function CommandManager(_arg1:Enforcer){
            this._listeners = new Dictionary();
        }
        public static function getInstance():CommandManager{
            return ((_instance = ((_instance) || (new CommandManager(new Enforcer())))));
        }

        public function run(_arg1, _arg2:Object=null, _arg3:Function=null, _arg4:Function=null, _arg5:int=0):void{
            var _local6:Command;
            if (_arg1){
                if ((_arg1 is Class)){
                    _local6 = (new (_arg1)() as Command);
                } else {
                    _local6 = (_arg1 as Command);
                };
                _local6.body = _arg2;
                this._listeners[_local6] = {};
                if (_arg3 != null){
                    this._listeners[_local6].complete = _arg3;
                    _local6.addEventListener(CommandEvent.COMPLETE, _arg3, false, _arg5, true);
                };
                if (_arg4 != null){
                    this._listeners[_local6].error = _arg4;
                    _local6.addEventListener(CommandEvent.ERROR, _arg4, false, _arg5, true);
                };
            };
            _local6.addEventListener(CommandEvent.COMPLETE, this.handleCommandEvents, false, _arg5, true);
            _local6.addEventListener(CommandEvent.ERROR, this.handleCommandEvents, false, _arg5, true);
            _local6.execute();
        }
        private function handleCommandEvents(_arg1:CommandEvent):void{
            var _local2:Command = (_arg1.target as Command);
            var _local3:Object = (this._listeners[_local2] as Object);
            if (!_local3){
                return;
            };
            if (_local3.complete != null){
                _local2.removeEventListener(CommandEvent.COMPLETE, _local3.complete);
                _local3.complete = null;
            };
            if (_local3.error != null){
                _local2.removeEventListener(CommandEvent.COMPLETE, _local3.error);
                _local3.error = null;
            };
            delete this._listeners[_local2];
        }

    }
}//package com.qzone.qfa.managers

class Enforcer {

    public function Enforcer(){