home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Esportes
/
CrossingCup.swf
/
scripts
/
__Packages
/
com
/
bourre
/
events
/
EventBroadcaster.as
< prev
next >
Wrap
Text File
|
2007-12-11
|
5KB
|
187 lines
class com.bourre.events.EventBroadcaster implements com.bourre.events.IEventDispatcher
{
static var _bInitialization = com.bourre.core.HashCodeFactory;
function EventBroadcaster(owner)
{
this._oOwner = !owner ? this : owner;
this._init();
}
static function getInstance()
{
return !(com.bourre.events.EventBroadcaster._oI instanceof com.bourre.events.EventBroadcaster) ? com.bourre.events.EventBroadcaster._buildInstance() : com.bourre.events.EventBroadcaster._oI;
}
function getListenerArray(t)
{
return t != undefined ? this._oL[t] : this._aAll;
}
function listenerArrayExists(t)
{
return this._oL[t] != undefined;
}
function addListener(oL, f)
{
if(f)
{
oL = this._getEventProxy.apply(this,arguments);
}
if(this._aAll.insert(oL))
{
this._clean(!f ? com.bourre.core.HashCodeFactory.getKey(oL) : com.bourre.core.HashCodeFactory.getKey(oL.t));
}
}
function removeListener(oL)
{
this._clean(com.bourre.core.HashCodeFactory.getKey(oL));
this._aAll.remove(oL);
}
function removeAllListeners()
{
this._init();
}
function addEventListener(t, oL)
{
var _loc6_ = arguments[2];
if(_loc6_)
{
oL = this._getEventProxy.apply(this,arguments.splice(1));
}
if(!this._aAll.listenerExists(oL))
{
if(!this.listenerArrayExists(t))
{
this._oL[t] = new com.bourre.events.ListenerArray();
}
if(this.getListenerArray(t).insert(oL))
{
var _loc4_ = !_loc6_ ? com.bourre.core.HashCodeFactory.getKey(oL) : com.bourre.core.HashCodeFactory.getKey(oL.t);
if(this._oE[_loc4_] == undefined)
{
this._oE[_loc4_] = new Object();
}
this._oE[_loc4_][t] = oL;
}
}
}
function removeEventListener(t, oL)
{
if(this.listenerArrayExists(t))
{
var _loc3_ = this.getListenerArray(t);
if(_loc3_.remove(oL))
{
delete this._oE[com.bourre.core.HashCodeFactory.getKey(oL)][t];
if(_loc3_.isEmpty())
{
delete this._oL[t];
}
}
}
}
function removeAllEventListeners(t)
{
if(this.listenerArrayExists(t))
{
delete this._oL[t];
for(var _loc3_ in this._oE)
{
delete this._oE[_loc3_][t];
}
}
}
function broadcastEvent(e)
{
if(e.getTarget() == undefined)
{
e.setTarget(this._oOwner);
}
var _loc3_ = this.getListenerArray(e.getType());
if(_loc3_ != undefined)
{
this._broadcast(_loc3_,e);
}
if(this._aAll.length > 0)
{
this._broadcast(this._aAll,e);
}
}
function dispatchEvent(o)
{
var _loc3_ = new com.bourre.events.DynBasicEvent(o.type,o.target);
for(var _loc4_ in o)
{
if(o[_loc4_] != "type" && o[_loc4_] != "target")
{
_loc3_[_loc4_] = o[_loc4_];
}
}
this.broadcastEvent(_loc3_);
}
function isEmpty()
{
var _loc2_ = undefined;
for(_loc2_ in this._oL)
{
if(_loc2_)
{
break;
}
}
return this._aAll.length == 0 && _loc2_ == undefined;
}
function toString()
{
return com.bourre.log.PixlibStringifier.stringify(this);
}
static function _buildInstance()
{
com.bourre.events.EventBroadcaster._oI = new com.bourre.events.EventBroadcaster();
return com.bourre.events.EventBroadcaster._oI;
}
function _init()
{
this._oL = new Object();
this._aAll = new com.bourre.events.ListenerArray();
this._oE = new Object();
}
function _broadcast(aL, e)
{
var _loc5_ = aL.length;
while((_loc5_ = _loc5_ - 1) > -1)
{
var _loc2_ = aL[_loc5_];
var _loc4_ = typeof _loc2_;
if(_loc4_ == "object" || _loc4_ == "movieclip")
{
if(_loc2_.handleEvent != undefined)
{
_loc2_.handleEvent(e);
}
else
{
_loc2_[String(e.getType())](e);
}
}
else
{
_loc2_.apply(this,[e]);
}
}
}
function _clean(key)
{
if(this._oE[key] != undefined)
{
var _loc2_ = this._oE[key];
for(var _loc3_ in _loc2_)
{
this.removeEventListener(_loc3_,_loc2_[_loc3_]);
}
delete this._oE[key];
}
}
function _getEventProxy(oL, f)
{
return com.bourre.commands.Delegate.create.apply(com.bourre.commands.Delegate,[oL,f].concat(arguments.splice(2)));
}
}