Package | com.smartfoxserver.v2.requests |
Class | public class PublicMessageRequest |
Inheritance | PublicMessageRequest com.smartfoxserver.v2.requests.GenericMessageRequest |
A public message is dispatched to all the users in the specified Room, including the message sender (this allows showing messages in the correct order in the application interface); the corresponding event is the publicMessage event. It is also possible to send an optional object together with the message: it can contain custom parameters useful to transmit, for example, additional informations related to the message, like the text font or color, or other formatting details.
In case the target Room is not specified, the message is sent in the last Room joined by the sender.
NOTE: the publicMessage event is dispatched if the Room is configured to allow public messaging only (see the RoomSettings.permissions parameter).
See also
Method | Defined By | ||
---|---|---|---|
Creates a new PublicMessageRequest instance. | PublicMessageRequest |
PublicMessageRequest | () | Constructor |
public function PublicMessageRequest(message:String, params:ISFSObject = null, targetRoom:Room = null)
Creates a new PublicMessageRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
Parametersmessage:String — The message to be sent to all the users in the target Room.
| |
params:ISFSObject (default = null ) — An instance of SFSObject containing additional custom parameters to be sent to the message recipients (for example the color of the text, etc).
| |
targetRoom:Room (default = null ) — The Room object corresponding to the Room where the message should be dispatched; if null , the last Room joined by the user is used.
|
See also
private function someMethod():void { sfs.addEventListener(SFSEvent.PUBLIC_MESSAGE, onPublicMessage); // Send a public message sfs.send(new PublicMessageRequest("Hello everyone!")); } private function onPublicMessage(evt:SFSEvent):void { // As messages are forwarded to the sender too, // I have to check if I am the sender var sender:User = evt.params.sender; if (sender == sfs.mySelf) trace("I said:", evt.params.message); else trace("User " + sender.name + " said:", evt.params.message); }