Page 1 of 1

Placing Text into a SmartFoxbits ChatBox

Posted: 24 Jan 2014, 14:30
by Wavemannova
I'd like to post some information in a chatBox from a button event in flash.

For example my game will have 4 players, when the first player chooses (lets call him Dave) their seat I want a message in the chat box saying "Dave is now Player 1".

When I use the PublicMessageRequest function it preludes the user name in the chat that comes into the chatBox:
Example:

Dave says: Dave is now Player 1

Is there a method I am missing that will allow me to send chat into a SmartFoxbits chatBox other than PublicMessageRequest?

Re: Placing Text into a SmartFoxbits ChatBox

Posted: 25 Jan 2014, 15:18
by Bax
You could send a request to a server side Extension and from there send a moderator message to all the users in the Room.
The ChatBox component is capable of displaying moderator messages.

Re: Placing Text into a SmartFoxbits ChatBox

Posted: 27 Jan 2014, 02:36
by Wavemannova
Thanks for the quick response Bax. When I try to implement the ModeratorMessageRequest function I get a compiler error in Flash 1180: Call to a possibly undefined method ModeratorMessageRequest.

I do have the appropriate import calls to
import com.smartfoxserver.v2.SmartFox;
import com.smartfoxserver.v2.requests.*;
import com.smartfoxserver.v2.core.SFSEvent;

in my code

Code: Select all

private function modMethod():void {
         sfs.addEventListener(SFSEvent.MODERATOR_MESSAGE, onModMsg);
         var recipMode:MessageRecipientMode = new MessageRecipientMode(MessageRecipientMode.TO_ROOM, sfs.lastJoinedRoom);
         sfs.send(new ModeratorMessageRequest("Dave is now Player 1", recipMode));
      }
      
private function onModMsg(evt:SFSEvent):void {
        trace ("received mod response");
      }

Re: Placing Text into a SmartFoxbits ChatBox

Posted: 27 Jan 2014, 08:44
by Bax
I'm not sure why Flash can't find those classes, but anyway that's not the right approach: if you send a moderator request from the client, that user must have moderation privileges. You should handle this on the server side using a custom Extension: the client sends a message to the Extension and the server sends a moderator message.

If you don't want to use an Extension for that purpose only (maybe your game doesn't need it for other purposes), then you could use for example an ObjectMessageRequest: send a message to all the clients in the Room, and make all the clients write a string in the ChatBox by accessing the internal text area directly (you have a public property on the ChatBox class).