home *** CD-ROM | disk | FTP | other *** search
/ ftp.novell.com / 2014.06.ftp.novell.com.tar / ftp.novell.com / forge / camtasia.msi / Cabs.w1.cab / camtasia_player_ext.swf9 / scripts / __Packages / com / techsmith / events / EventDispatcher.as next >
Text File  |  2009-08-17  |  3KB  |  124 lines

  1. class com.techsmith.events.EventDispatcher implements com.techsmith.events.IEventDispatcher
  2. {
  3.    var eventStore = null;
  4.    var active = false;
  5.    function EventDispatcher()
  6.    {
  7.       this.eventStore = new Object();
  8.    }
  9.    function addEventListener(event, scope)
  10.    {
  11.       if(!this.active)
  12.       {
  13.          if(this.eventStore[event] == undefined)
  14.          {
  15.             this.eventStore[event] = [];
  16.          }
  17.          var _loc4_ = this.eventStore[event].length;
  18.          var _loc5_ = _loc4_ - 1;
  19.          while(_loc5_ > -1)
  20.          {
  21.             if(this.eventStore[event][_loc5_].scope === scope)
  22.             {
  23.                return undefined;
  24.             }
  25.             _loc5_ = _loc5_ - 1;
  26.          }
  27.          this.eventStore[event].push({event:event,scope:scope});
  28.       }
  29.       else
  30.       {
  31.          if(this.eventStore.addqueue == undefined)
  32.          {
  33.             this.eventStore.addqueue = [];
  34.          }
  35.          this.eventStore.addqueue.push({event:event,scope:scope});
  36.       }
  37.    }
  38.    function removeEventListener(event, scope)
  39.    {
  40.       if(!this.active)
  41.       {
  42.          var _loc4_ = this.eventStore[event].length;
  43.          var _loc5_ = _loc4_ - 1;
  44.          while(_loc5_ > -1)
  45.          {
  46.             if(this.eventStore[event][_loc5_].scope === scope)
  47.             {
  48.                this.eventStore[event].splice(_loc5_,1);
  49.             }
  50.             _loc5_ = _loc5_ - 1;
  51.          }
  52.       }
  53.       else
  54.       {
  55.          if(this.eventStore.remqueue == undefined)
  56.          {
  57.             this.eventStore.remqueue = [];
  58.          }
  59.          this.eventStore.remqueue.push({event:event,scope:scope});
  60.       }
  61.    }
  62.    function removeEventListeners(event)
  63.    {
  64.       this.eventStore[event].splice(0);
  65.    }
  66.    function removeAllListeners()
  67.    {
  68.       for(var i in this.eventStore)
  69.       {
  70.          if(this.eventStore[i] instanceof Array)
  71.          {
  72.             this.eventStore[i].splice(0);
  73.          }
  74.       }
  75.    }
  76.    function dispatchEvent(eventObj)
  77.    {
  78.       this.active = true;
  79.       var _loc3_ = this.eventStore[eventObj.type];
  80.       var _loc4_ = this.eventStore[eventObj.type].length;
  81.       var _loc5_ = 0;
  82.       while(_loc5_ < _loc4_)
  83.       {
  84.          var _loc6_ = this.eventStore[eventObj.type][_loc5_].event;
  85.          if(_loc3_[_loc5_].scope instanceof Function)
  86.          {
  87.             _loc3_[_loc5_].scope(eventObj);
  88.          }
  89.          else
  90.          {
  91.             _loc3_[_loc5_].scope[_loc6_].apply(_loc3_[_loc5_].scope,[eventObj]);
  92.          }
  93.          _loc5_ = _loc5_ + 1;
  94.       }
  95.       this.active = false;
  96.       this.delayQueue();
  97.    }
  98.    function delayQueue()
  99.    {
  100.       var _loc2_ = this.eventStore.remqueue.length;
  101.       if(_loc2_ > 0)
  102.       {
  103.          var _loc3_ = 0;
  104.          while(_loc3_ < _loc2_)
  105.          {
  106.             this.addEventListener(this.eventStore.remqueue[_loc3_].event,this.eventStore.remqueue[_loc3_].scope);
  107.             _loc3_ = _loc3_ + 1;
  108.          }
  109.          this.eventStore.remqueue.splice(0);
  110.       }
  111.       _loc2_ = this.eventStore.addqueue.length;
  112.       if(this.eventStore.addqueue.length > 0)
  113.       {
  114.          var _loc4_ = 0;
  115.          while(_loc4_ < _loc2_)
  116.          {
  117.             this.addEventListener(this.eventStore.addqueue[_loc4_].event,this.eventStore.addqueue[_loc4_].scope);
  118.             _loc4_ = _loc4_ + 1;
  119.          }
  120.          this.eventStore.addqueue.splice(0);
  121.       }
  122.    }
  123. }
  124.