Packagecom.smartfoxserver.v2.requests
Classpublic class SetRoomVariablesRequest
InheritanceSetRoomVariablesRequest Inheritance com.smartfoxserver.v2.requests.BaseRequest

Sets one or more custom Room Variables in a Room.

When a Room Variable is set, the roomVariablesUpdate event is dispatched to all the users in the target Room, including the user who updated it. Also, if the Room Variable is global (see the SFSRoomVariable class description), the event is dispatched to all users who subscribed the Group to which the target Room is associated.

View the examples

See also

roomVariablesUpdate event
SFSRoomVariable


Public Methods
 MethodDefined By
  
SetRoomVariablesRequest(roomVariables:Array, room:Room = null)
Creates a new SetRoomVariablesRequest instance.
SetRoomVariablesRequest
Constructor Detail
SetRoomVariablesRequest()Constructor
public function SetRoomVariablesRequest(roomVariables:Array, room:Room = null)

Creates a new SetRoomVariablesRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

Parameters
roomVariables:Array — A list of RoomVariable objects representing the Room Variables to be set.
 
room:Room (default = null) — A Room object representing the Room where to set the Room Variables; if null, the last Room joined by the current user is used.

See also

Examples
The following example sets a number of Room Variables and handles the respective update event:
     
     private function someMethod():void
     {
         sfs.addEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, onRoomVarsUpdate);
         
         // Create some Room Variables
         var roomVars:Array = [];
         roomVars.push(new SFSRoomVariable("gameStarted", false));
         roomVars.push(new SFSRoomVariable("gameType", "Snooker"));
         roomVars.push(new SFSRoomVariable("minRank", 10));
         
         sfs.send(new SetRoomVariablesRequest(roomVars));
     }
     
     private function onRoomVarsUpdate(evt:SFSEvent):void
     {
         var changedVars:Array = evt.params.changedVars as Array;
         var room:Room = evt.params.room as Room;
         
         // Check if the "gameStarted" variable was changed
         if (changedVars.indexOf("gameStarted") != -1)
         {
             if (room.getVariable("gameStarted").getBoolValue() == true)
                 trace("Game started");
             else
                 trace("Game stopped");
         }
     }