Package | com.smartfoxserver.v2.requests |
Class | public class ObjectMessageRequest |
Inheritance | ObjectMessageRequest com.smartfoxserver.v2.requests.GenericMessageRequest |
The data object is delivered to the selected users (or all users excluding the sender) inside the target Room by means of the objectMessage event. It can be useful to send game data, like for example the target coordinates of the user's avatar in a virtual world.
See also
Method | Defined By | ||
---|---|---|---|
Creates a new ObjectMessageRequest instance. | ObjectMessageRequest |
ObjectMessageRequest | () | Constructor |
public function ObjectMessageRequest(obj:ISFSObject, targetRoom:Room = null, recipients:Array = null)
Creates a new ObjectMessageRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
Parametersobj:ISFSObject — An instance of SFSObject containing custom parameters to be sent to the message recipients.
| |
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.
| |
recipients:Array (default = null ) — A list of User objects corresponding to the message recipients; if null , the message is sent to all users in the target Room (except the sender himself).
|
See also
private function someMethod():void { sfs.addEventListener(SFSEvent.OBJECT_MESSAGE, onObjectMessage); // Send my movement to all players var dataObj:ISFSObject = new SFSObject(); dataObj.putInt("x", myCharacter.x); dataObj.putInt("y", myCharacter.y); sfs.send(new ObjectMessageRequest(dataObj)); } private function onObjectMessage(evt:SFSEvent):void { var dataObj:ISFSObject = evt.params.message as SFSObject; var sender:User = evt.params.sender; var character:Sprite = getUserCharacter(sender.id); character.x = dataObj.getInt("x"); character.y = dataObj.getInt("y"); }