Discussion list for Unity developers.
unity-dev at moock.org
Wed Aug 8 11:12:42 CDT 2007
hi drew,
The following code uses invokeOnClient() to send a private message from
one client to another. The method invoked remotely on the target client
is privateMessage(). Here, the client ID is hard coded as "25" but in a
real application it would normally be retrieved programmatically,
perhaps from the user's selection in a client list or from user-entered
text.
var recipientClientID:String = "25";
theUClient.invokeOnClient("privateMessage", recipientClientID, msg);
And here is the privateMessage() method, defined in a UClient subclass.
public function privateMessage (clientID:String, message:String):Void {
this.chatField_txt.text += "Private message: " + message);
}
Here's another example privateMessage() method that forwards the call to
ChatRoom.privateMessage() for processing. ChatRoom is a URoom subclass
that implements the logical response to a private message.
public function privateMessage (clientID:String, message:String):Void {
// Retrieve a list of rooms that this client is in.
var rooms:Array =
getRemoteClientManager().getClient(getClientID()).getRoomIDs();
// Send the private message to all rooms this client is in.
for (var i:Number = rooms.length; --i >= 0; ) {
// Cast to ChatRoom.
ChatRoom(getRoomManager().getRoom(rooms[i])).privateMessage(clientID,
message);
}
}
colin
Discussion list for Unity developers. wrote:
> Hi All,
>
> I am currently working on extending uAvatarChat with several features. I've had some success, but I've encountered some problems too. I'm trying to implement private messages in the chat. I've been looking at the documentation on method invokeOnClient(), and I understand that I must use this to call a 'privateMessage' method... I'm confused where to go from here though - what does the privateMessage function need to do in order to get the message to the incoming textfield of (only) the intended client? I've had a look at the uClientChat demo files, but I'm still confused with the steps that are taken from when the message is sent to when it is received, and how to get this working in uAvatarChat. Could anyone help with an explanation or some advice on how I could implement this?
>
> Thanks,
>
> drew
> --
> you're a unity-dev subscriber. to unsubscribe, visit www.moock.org/mailman/listinfo/unity-dev/
>
> superb hosting for this list and moock.org is generously provided by Rackspace. See: http://www.rackspace.com/?supbid=moock