Package | com.smartfoxserver.v2.requests.buddylist |
Class | public class BuddyMessageRequest |
Inheritance | BuddyMessageRequest com.smartfoxserver.v2.requests.GenericMessageRequest |
Messages sent to buddies using the BuddyMessageRequest request are similar to the standard private messages (see the PrivateMessageRequest request) but are specifically designed for the Buddy List system: they don't require any Room parameter, nor they require that users joined a Room. Additionally, buddy messages are subject to specific validation, such as making sure that the recipient is in the sender's buddies list and the sender is not blocked by the recipient.
If the operation is successful, a buddyMessage event is dispatched in both the sender and recipient clients.
NOTE: this request can be sent if the Buddy List system was previously initialized only (see the InitBuddyListRequest request description).
See also
Method | Defined By | ||
---|---|---|---|
Creates a new BuddyMessageRequest instance. | BuddyMessageRequest |
BuddyMessageRequest | () | Constructor |
public function BuddyMessageRequest(message:String, targetBuddy:Buddy, params:ISFSObject = null)
Creates a new BuddyMessageRequest 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 a buddy.
| |
targetBuddy:Buddy — The Buddy object corresponding to the message recipient.
| |
params:ISFSObject (default = null ) — An instance of SFSObject containing additional custom parameters (e.g. the message color, an emoticon id, etc).
|
See also
private function someMethod():void { sfs.addEventListener(SFSBuddyEvent.BUDDY_MESSAGE, onBuddyMessage); // Get the recipient of the message, in this case my buddy Jack var buddy:Buddy = sfs.buddyManager.getBuddyByName("Jack"); // Send a message to Jack sfs.send(new BuddyMessageRequest("Hello Jack!", buddy)); } private function onBuddyMessage(evt:SFSBuddyEvent):void { // As messages are forwarded to the sender too, // I have to check if I am the sender var isItMe:Boolean = evt.params.isItMe; var sender:Buddy = evt.params.buddy; if (isItMe) trace("I said:", evt.params.message); else trace("My buddy " + sender.name + " said:", evt.params.message); }