Page 1 of 1

A simple message

Posted: 01 May 2010, 21:57
by Eralmidia
Hi, I was just wondering, does the sendPriavteMessage function trigger the onPrivateMessage eventhandler on both sender and receiver?

I try this code, which basicly is the same as in the docs:

Code: Select all

			btnInvitePlayer.addEventListener(MouseEvent.CLICK,btnInvitePlayerClick)
			smartfox.addEventListener(SFSEvent.onPrivateMessage, onPrivateMessageHandler);
		}
		private function btnInvitePlayerClick(e:Event)
		{
			if(lstPlayers.selectedItem!=null)
			{
				trace(lstPlayers.selectedItem.data);
				smartfox.sendPrivateMessage("test msg",lstPlayers.selectedItem.data);
			}
			else
			{
				trace("please select a player")
			}
		}
		private function onPrivateMessageHandler(e:SFSEvent)
		{
			trace("User " + e.params.sender.getName() + " sent the following private message: " + e.params.message)
		}

Now, while this does work, there is a small problem.The trace from the onPrivateMessageHandler is traced twice. The trace in btnInvitePlayerClick does however not.

Posted: 02 May 2010, 21:25
by BigFIsh
Make sure you remove any old SFS listeners or use "weak reference" when setting up listeners.

Posted: 02 May 2010, 22:34
by Eralmidia
Well, this is the first time in the project I create this handler, so it really shouldt fire twice? I have a few handlers in some other movieclip class files, for login an joining room, and the smartfox client object is passed as an argument when they are created.

Tried setting up all the handlers with weak refference, nothing changed.

Posted: 02 May 2010, 23:23
by Eralmidia
I found this post that Lapo replied to on a similar question:

http://forums.smartfoxserver.com/viewto ... atemessage

Guess this means that the answer to my initial question is yes, Lapo? The message is send to the receiver, but also to the onPrivateMessage handler of the sender?

Posted: 03 May 2010, 00:24
by BigFIsh
Whops, I mis-read your question. Yes, both sender and receiver receives the onPrivateMessage event.

Posted: 03 May 2010, 01:00
by Eralmidia
Seems like I misred too. It is actually stated in the API docs that ist broadcasted to both sender and receiver. Thanks :)