||unity-dev|| how to add a URoomListener.onClientListInited() event to UClient 2.0.1

Discussion list for Unity developers. unity-dev at moock.org
Wed Sep 27 11:26:48 CDT 2006


recently we had a customer that needed a 
URoomListener.onClientListInited() event. in UClient 2.0.1 we 
unfortunately did not include that event, but it is possible to 
dynamically add it.

for posterity, I'm posting the required code here.

the customer needed the event in order to detect when a client is the 
first client in a room. to check that condition, a room listener needs 
to know when the room's client list initialization is complete. when 
client list initialization is complete, if the number of clients in the 
room is 1, then that client is the first client in the room.

here are the steps required to add URoomListener.onClientListInited() to 
UClient 2.0.1:

1) add the following code to the application's UClient subclass 
constructor function.
//=====
var URoomClass = org.moock.unity.URoom;
URoomClass.prototype.fireOnClientListInited = function () {
   var listeners = this.listenerList.getListeners();
   var e = new org.moock.unity.URoomEvent(this, null, null, null, null);

   // Trigger event on listeners.
   for (var i = 0; i < listeners.length; i++) {
     listeners[i].onClientListInited(e);
   }
}

URoomClass.prototype.setClientListInited = function () {
   this.clntListInited = true;
   this.fireOnClientListInited();
}
//=====

2) add the following event handler function to each room's listener 
classes (which are usually subclasses of URoomView):

public function onClientListInited (e:URoomEvent):Void {
   trace("onClientListInited fired.")
   // If room.getClientIDs().length is 1, then the client
   // is the only client in the room upon entering.
   trace("Number of clients in room: " + room.getClientIDs().length)
}


colin


More information about the unity-dev mailing list