Packagecom.smartfoxserver.v2.requests.buddylist
Classpublic class SetBuddyVariablesRequest
InheritanceSetBuddyVariablesRequest Inheritance com.smartfoxserver.v2.requests.BaseRequest

Sets one or more Buddy Variables for the current user.

This operation updates the Buddy object representing the user in all the buddies lists in which the user was added as a buddy. If the operation is successful, a buddyVariablesUpdate event is dispatched to all the owners of those buddies lists and to the user who updated his variables too.

The Buddy Variables can be persisted, which means that their value will be saved even it the user disconnects and it will be restored when he connects again. In order to make a variable persistent, put the constant SFSBuddyVariable.OFFLINE_PREFIX before its name. Read the SmartFoxServer 2X documentaion about the Buddy List API for more informations.

NOTE: this request can be sent if the Buddy List system was previously initialized only (see the InitBuddyListRequest request description) and the current user state in the system is "online".

View the examples

See also

BuddyVariable
buddyVariablesUpdate event
InitBuddyListRequest


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

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

Parameters
buddyVariables:Array — A list of BuddyVariable objects representing the Buddy Variables to be set.

See also

Examples
The following example sets some Buddy Variables for the current user, one of which is persistent; the example also handles changes made by the user or by his buddies:
     
     private function someMethod():void
     {
         sfs.addEventListener(SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, onBuddyVarsUpdate);
         
         // Create two Buddy Variables containing the title and artist of the song I'm listening to
         var songTitle:BuddyVariable = new SFSBuddyVariable("songTitle", "Ascension");
         var songAuthor:BuddyVariable = new SFSBuddyVariable("songAuthor", "Mike Oldfield");
         
         // Create a persistent Buddy Variable containing my mood message
         var mood:BuddyVariable = new SFSBuddyVariable(SFSBuddyVariable.OFFLINE_PREFIX + "mood", "I Need SmartFoxServer 2X desperately!");
         
         // Set my Buddy Variables
         var vars:Array = [songTitle, songAuthor, mood];
         sfs.send(new SetBuddyVariablesRequest(vars));
     }
     
     private function onBuddyVarsUpdate(evt:SFSBuddyEvent):void
     {
         // As the update event is dispatched to me too,
         // I have to check if I am the one who changed his Buddy Variables
         
         var isItMe:Boolean = evt.params.isItMe;
         
         if (isItMe)
         {
             trace("I've updated the following Buddy Variables:");
             
             for (var i:int = 0; i < evt.params.changedVars.length; i++)
             {
                 var bVarName:String = evt.params.changedVars[i];
                 
                 trace(bVarName, "-->", sfs.buddyManager.getMyVariable(bVarName).getValue());
             }
         }
         else
         {
             var buddyName:String = evt.params.buddy.name;
             
             trace("My buddy " + buddyName + " updated the following Buddy Variables:");
             
             for (var i:int = 0; i < evt.params.changedVars.length; i++)
             {
                 var bVarName:String = evt.params.changedVars[i];
                 
                 trace(bVarName, "-->", sfs.buddyManager.getBuddyByName(buddyName).getVariable(bVarName).getValue());
             }
         }
     }