[ascoders] Re: [ascoders]ASBroadcaster - Bug behoben - Performanz vorhanden

  • From: "bokel" <actionscript@xxxxxxxxxxxx>
  • To: <ascoders@xxxxxxxxxxxxx>
  • Date: Sun, 20 Apr 2003 12:23:11 +0200

Guten Morgen Holger,

hier ist mal eine Version, die den originalen Broadcast benutzt,
und bei der man während des Broadcasts löschen kann.
Dazu wird vor dem Broadcast einfach die ListenerListe
kopiert und die Funktionen umgebogen, die die ListenerListe
verändern.

<code>
function TurboBroadcaster(){
}

o = TurboBroadcaster;

o.broadcastMessage = function(){
 this._saveListeners = this._listeners;
 this._listeners = this._listeners.slice(0);
 //
 this.removeListener = this.removeListenerWhileBroadcasting;
 this.addListener = this.addListenerWhileBroadcasting;
 //
 this.orgBroadcastMessage.apply(this, arguments);
 //
 this._listeners = this._saveListeners;
 //
 this.removeListener = this.orgRemoveListener;
 this.addListener = this.orgAddListener;
}

o.removeListenerWhileBroadcasting = function(obj){
 var tmpListeners = this._listeners;
 this._listeners = this._saveListeners;
 var result = this.orgRemoveListener(obj);
 this._listeners = tmpListeners;
 return result;
}

o.addListenerWhileBroadcasting = function(obj){
 var tmpListeners = this._listeners;
 this._listeners = this._saveListeners;
 var result = this.orgAddListener(obj);
 this._listeners = tmpListeners;
 return result;
}

o.initialize = function(obj){
 ASBroadcaster.initialize(obj);
 obj.orgRemoveListener = obj.removeListener;
 obj.orgAddListener = obj.addListener;
 obj.orgBroadcastMessage = obj.broadcastMessage;
 //
 obj.broadcastMessage = this.broadcastMessage;
 obj.removeListenerWhileBroadcasting = this.removeListenerWhileBroadcasting
 obj.addListenerWhileBroadcasting = this.addListenerWhileBroadcasting;
}

Welt = function (pIntKaefer) {
 TurboBroadcaster.initialize(this);
 ASSetPropFlags(this, null, 0, 1);
 for(var i in this) trace(i);
 //
 while (pIntKaefer--)
  new Kaefer(this, pIntKaefer);
}

Welt.prototype.armageddon = function () {
 this.broadcastMessage('onArmageddon');
}

Kaefer = function (pObjWelt, pIntId) {
 this.intId = pIntId;
 this.objWelt = pObjWelt;
 this.objWelt.addListener(this);
}

Kaefer.prototype.onArmageddon = function () {
 trace(this.intId + ' hat das zeitliche gesegnet');
 this.objWelt.removeListener(this);
}

objWelt = new Welt(10);
objWelt.armageddon();
</code>




----- Original Message -----
From: "Holger Kohnen" <h_kohnen@xxxxxx>
To: <ascoders@xxxxxxxxxxxxx>
Sent: Saturday, April 19, 2003 7:44 PM
Subject: [ascoders] Re: [ascoders]ASBroadcaster - Bug behoben - Performanz 
vorhanden


> Stimmt schon, Programmierer sind halt schreibfaul,
> die Idee klingt gut sogar sehr gut, kann grad nicht mehr
> darüber nachdenken, das Gehirn streikt irgendwie,
> morgen gehts hoffentlich wieder...:-)
> grüße, Holger

------------------------------------------------------
Archiv   : //www.freelists.org/archives/ascoders/
Optionen : //www.freelists.org/list/ascoders
------------------------------------------------------

Other related posts: