Packagecom.smartfoxserver.v2.requests
Classpublic class SetUserVariablesRequest
InheritanceSetUserVariablesRequest Inheritance com.smartfoxserver.v2.requests.BaseRequest

Sets one or more custom User Variables for the current user.

When a User Variable is set, the userVariablesUpdate event is dispatched to all the users in all the Rooms joined by the current user, including himself.

NOTE: the userVariablesUpdate event is dispatched to users in a specific Room only if it is configured to allow this event (see the RoomSettings.permissions parameter).

View the examples

See also

userVariablesUpdate event
RoomSettings.permissions


Public Methods
 MethodDefined By
  
SetUserVariablesRequest(userVariables:Array)
Creates a new SetUserVariablesRequest instance.
SetUserVariablesRequest
Constructor Detail
SetUserVariablesRequest()Constructor
public function SetUserVariablesRequest(userVariables:Array)

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

Parameters
userVariables:Array — A list of UserVariable objects representing the User Variables to be set.

See also

Examples
The following example sets a number of User Variables and handles the respective update event:
     
     private function someMethod():void
     {
         sfs.addEventListener(SFSEvent.USER_VARIABLES_UPDATE, onUserVarsUpdate);
         
         // Create some User Variables
         var userVars:Array = [];
         userVars.push(new SFSUserVariable("avatarType", "SwedishCook"));
         userVars.push(new SFSUserVariable("country", "Sweden"));
         userVars.push(new SFSUserVariable("x", 10));
         userVars.push(new SFSUserVariable("y", 5));
         
         sfs.send(new SetUserVariablesRequest(userVars));
     }
     
     private function onUserVarsUpdate(evt:SFSEvent):void
     {
         var changedVars:Array = evt.params.changedVars as Array;
         var user:User = evt.params.user as User;
         
         // Check if the user changed his x and y user variables
         if (changedVars.indexOf("x") != -1 || changedVars.indexOf("y") != -1)
         {
             // Move the user avatar to a new position
             ...
         }
     }