Packagecom.smartfoxserver.v2.requests
Classpublic class ObjectMessageRequest
InheritanceObjectMessageRequest Inheritance com.smartfoxserver.v2.requests.GenericMessageRequest

Sends an object containing custom data to all users in a Room, or a subset of them.

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.

View the examples

See also

objectMessage event


Public Methods
 MethodDefined By
  
ObjectMessageRequest(obj:ISFSObject, targetRoom:Room = null, recipients:Array = null)
Creates a new ObjectMessageRequest instance.
ObjectMessageRequest
Constructor Detail
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.

Parameters
obj: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

Examples
The following example sends the player's character movement coordinates and handles the respective event (note: the myCharacter instance is supposed to be the user sprite on the stage, while the getUserCharacter method retrieves the sprite of other users' characters):
     
     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");
     }