A simple message

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
Eralmidia
Posts: 9
Joined: 25 Apr 2010, 02:34

A simple message

Post 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.
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

Make sure you remove any old SFS listeners or use "weak reference" when setting up listeners.
Smartfox's forum is my daily newspaper.
Eralmidia
Posts: 9
Joined: 25 Apr 2010, 02:34

Post 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.
Eralmidia
Posts: 9
Joined: 25 Apr 2010, 02:34

Post 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?
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

Whops, I mis-read your question. Yes, both sender and receiver receives the onPrivateMessage event.
Smartfox's forum is my daily newspaper.
Eralmidia
Posts: 9
Joined: 25 Apr 2010, 02:34

Post by Eralmidia »

Seems like I misred too. It is actually stated in the API docs that ist broadcasted to both sender and receiver. Thanks :)
Post Reply