home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Esportes / CrossingCup.swf / scripts / __Packages / com / bourre / events / EventBroadcaster.as < prev    next >
Text File  |  2007-12-11  |  5KB  |  187 lines

  1. class com.bourre.events.EventBroadcaster implements com.bourre.events.IEventDispatcher
  2. {
  3.    static var _bInitialization = com.bourre.core.HashCodeFactory;
  4.    function EventBroadcaster(owner)
  5.    {
  6.       this._oOwner = !owner ? this : owner;
  7.       this._init();
  8.    }
  9.    static function getInstance()
  10.    {
  11.       return !(com.bourre.events.EventBroadcaster._oI instanceof com.bourre.events.EventBroadcaster) ? com.bourre.events.EventBroadcaster._buildInstance() : com.bourre.events.EventBroadcaster._oI;
  12.    }
  13.    function getListenerArray(t)
  14.    {
  15.       return t != undefined ? this._oL[t] : this._aAll;
  16.    }
  17.    function listenerArrayExists(t)
  18.    {
  19.       return this._oL[t] != undefined;
  20.    }
  21.    function addListener(oL, f)
  22.    {
  23.       if(f)
  24.       {
  25.          oL = this._getEventProxy.apply(this,arguments);
  26.       }
  27.       if(this._aAll.insert(oL))
  28.       {
  29.          this._clean(!f ? com.bourre.core.HashCodeFactory.getKey(oL) : com.bourre.core.HashCodeFactory.getKey(oL.t));
  30.       }
  31.    }
  32.    function removeListener(oL)
  33.    {
  34.       this._clean(com.bourre.core.HashCodeFactory.getKey(oL));
  35.       this._aAll.remove(oL);
  36.    }
  37.    function removeAllListeners()
  38.    {
  39.       this._init();
  40.    }
  41.    function addEventListener(t, oL)
  42.    {
  43.       var _loc6_ = arguments[2];
  44.       if(_loc6_)
  45.       {
  46.          oL = this._getEventProxy.apply(this,arguments.splice(1));
  47.       }
  48.       if(!this._aAll.listenerExists(oL))
  49.       {
  50.          if(!this.listenerArrayExists(t))
  51.          {
  52.             this._oL[t] = new com.bourre.events.ListenerArray();
  53.          }
  54.          if(this.getListenerArray(t).insert(oL))
  55.          {
  56.             var _loc4_ = !_loc6_ ? com.bourre.core.HashCodeFactory.getKey(oL) : com.bourre.core.HashCodeFactory.getKey(oL.t);
  57.             if(this._oE[_loc4_] == undefined)
  58.             {
  59.                this._oE[_loc4_] = new Object();
  60.             }
  61.             this._oE[_loc4_][t] = oL;
  62.          }
  63.       }
  64.    }
  65.    function removeEventListener(t, oL)
  66.    {
  67.       if(this.listenerArrayExists(t))
  68.       {
  69.          var _loc3_ = this.getListenerArray(t);
  70.          if(_loc3_.remove(oL))
  71.          {
  72.             delete this._oE[com.bourre.core.HashCodeFactory.getKey(oL)][t];
  73.             if(_loc3_.isEmpty())
  74.             {
  75.                delete this._oL[t];
  76.             }
  77.          }
  78.       }
  79.    }
  80.    function removeAllEventListeners(t)
  81.    {
  82.       if(this.listenerArrayExists(t))
  83.       {
  84.          delete this._oL[t];
  85.          for(var _loc3_ in this._oE)
  86.          {
  87.             delete this._oE[_loc3_][t];
  88.          }
  89.       }
  90.    }
  91.    function broadcastEvent(e)
  92.    {
  93.       if(e.getTarget() == undefined)
  94.       {
  95.          e.setTarget(this._oOwner);
  96.       }
  97.       var _loc3_ = this.getListenerArray(e.getType());
  98.       if(_loc3_ != undefined)
  99.       {
  100.          this._broadcast(_loc3_,e);
  101.       }
  102.       if(this._aAll.length > 0)
  103.       {
  104.          this._broadcast(this._aAll,e);
  105.       }
  106.    }
  107.    function dispatchEvent(o)
  108.    {
  109.       var _loc3_ = new com.bourre.events.DynBasicEvent(o.type,o.target);
  110.       for(var _loc4_ in o)
  111.       {
  112.          if(o[_loc4_] != "type" && o[_loc4_] != "target")
  113.          {
  114.             _loc3_[_loc4_] = o[_loc4_];
  115.          }
  116.       }
  117.       this.broadcastEvent(_loc3_);
  118.    }
  119.    function isEmpty()
  120.    {
  121.       var _loc2_ = undefined;
  122.       for(_loc2_ in this._oL)
  123.       {
  124.          if(_loc2_)
  125.          {
  126.             break;
  127.          }
  128.       }
  129.       return this._aAll.length == 0 && _loc2_ == undefined;
  130.    }
  131.    function toString()
  132.    {
  133.       return com.bourre.log.PixlibStringifier.stringify(this);
  134.    }
  135.    static function _buildInstance()
  136.    {
  137.       com.bourre.events.EventBroadcaster._oI = new com.bourre.events.EventBroadcaster();
  138.       return com.bourre.events.EventBroadcaster._oI;
  139.    }
  140.    function _init()
  141.    {
  142.       this._oL = new Object();
  143.       this._aAll = new com.bourre.events.ListenerArray();
  144.       this._oE = new Object();
  145.    }
  146.    function _broadcast(aL, e)
  147.    {
  148.       var _loc5_ = aL.length;
  149.       while((_loc5_ = _loc5_ - 1) > -1)
  150.       {
  151.          var _loc2_ = aL[_loc5_];
  152.          var _loc4_ = typeof _loc2_;
  153.          if(_loc4_ == "object" || _loc4_ == "movieclip")
  154.          {
  155.             if(_loc2_.handleEvent != undefined)
  156.             {
  157.                _loc2_.handleEvent(e);
  158.             }
  159.             else
  160.             {
  161.                _loc2_[String(e.getType())](e);
  162.             }
  163.          }
  164.          else
  165.          {
  166.             _loc2_.apply(this,[e]);
  167.          }
  168.       }
  169.    }
  170.    function _clean(key)
  171.    {
  172.       if(this._oE[key] != undefined)
  173.       {
  174.          var _loc2_ = this._oE[key];
  175.          for(var _loc3_ in _loc2_)
  176.          {
  177.             this.removeEventListener(_loc3_,_loc2_[_loc3_]);
  178.          }
  179.          delete this._oE[key];
  180.       }
  181.    }
  182.    function _getEventProxy(oL, f)
  183.    {
  184.       return com.bourre.commands.Delegate.create.apply(com.bourre.commands.Delegate,[oL,f].concat(arguments.splice(2)));
  185.    }
  186. }
  187.