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 >
Wrap
Text File
|
2009-08-17
|
3KB
|
124 lines
class com.techsmith.events.EventDispatcher implements com.techsmith.events.IEventDispatcher
{
var eventStore = null;
var active = false;
function EventDispatcher()
{
this.eventStore = new Object();
}
function addEventListener(event, scope)
{
if(!this.active)
{
if(this.eventStore[event] == undefined)
{
this.eventStore[event] = [];
}
var _loc4_ = this.eventStore[event].length;
var _loc5_ = _loc4_ - 1;
while(_loc5_ > -1)
{
if(this.eventStore[event][_loc5_].scope === scope)
{
return undefined;
}
_loc5_ = _loc5_ - 1;
}
this.eventStore[event].push({event:event,scope:scope});
}
else
{
if(this.eventStore.addqueue == undefined)
{
this.eventStore.addqueue = [];
}
this.eventStore.addqueue.push({event:event,scope:scope});
}
}
function removeEventListener(event, scope)
{
if(!this.active)
{
var _loc4_ = this.eventStore[event].length;
var _loc5_ = _loc4_ - 1;
while(_loc5_ > -1)
{
if(this.eventStore[event][_loc5_].scope === scope)
{
this.eventStore[event].splice(_loc5_,1);
}
_loc5_ = _loc5_ - 1;
}
}
else
{
if(this.eventStore.remqueue == undefined)
{
this.eventStore.remqueue = [];
}
this.eventStore.remqueue.push({event:event,scope:scope});
}
}
function removeEventListeners(event)
{
this.eventStore[event].splice(0);
}
function removeAllListeners()
{
for(var i in this.eventStore)
{
if(this.eventStore[i] instanceof Array)
{
this.eventStore[i].splice(0);
}
}
}
function dispatchEvent(eventObj)
{
this.active = true;
var _loc3_ = this.eventStore[eventObj.type];
var _loc4_ = this.eventStore[eventObj.type].length;
var _loc5_ = 0;
while(_loc5_ < _loc4_)
{
var _loc6_ = this.eventStore[eventObj.type][_loc5_].event;
if(_loc3_[_loc5_].scope instanceof Function)
{
_loc3_[_loc5_].scope(eventObj);
}
else
{
_loc3_[_loc5_].scope[_loc6_].apply(_loc3_[_loc5_].scope,[eventObj]);
}
_loc5_ = _loc5_ + 1;
}
this.active = false;
this.delayQueue();
}
function delayQueue()
{
var _loc2_ = this.eventStore.remqueue.length;
if(_loc2_ > 0)
{
var _loc3_ = 0;
while(_loc3_ < _loc2_)
{
this.addEventListener(this.eventStore.remqueue[_loc3_].event,this.eventStore.remqueue[_loc3_].scope);
_loc3_ = _loc3_ + 1;
}
this.eventStore.remqueue.splice(0);
}
_loc2_ = this.eventStore.addqueue.length;
if(this.eventStore.addqueue.length > 0)
{
var _loc4_ = 0;
while(_loc4_ < _loc2_)
{
this.addEventListener(this.eventStore.addqueue[_loc4_].event,this.eventStore.addqueue[_loc4_].scope);
_loc4_ = _loc4_ + 1;
}
this.eventStore.addqueue.splice(0);
}
}
}