Packagecom.smartfoxserver.v2.core
Classpublic class SFSBuddyEvent
InheritanceSFSBuddyEvent Inheritance BaseEvent Inheritance flash.events.Event

SFSBuddyEvent is the class representing all the events related to the Buddy List system dispatched by the SmartFoxServer 2X ActionScript 3 API.

The SFSBuddyEvent parent class provides a public property called params which contains specific parameters depending on the event type.

See also

SFSEvent


Public Properties
 PropertyDefined By
 Inheritedparams : Object
Specifies the object containing the parameters of the event.
BaseEvent
Public Methods
 MethodDefined By
  
SFSBuddyEvent(type:String, params:Object)
Creates a new SFSBuddyEvent instance.
SFSBuddyEvent
  
clone():Event
[override] Duplicates the instance of the SFSBuddyEvent object.
SFSBuddyEvent
  
toString():String
[override] Generates a string containing all the properties of the SFSBuddyEvent object.
SFSBuddyEvent
Public Constants
 ConstantDefined By
  BUDDY_ADD : String = buddyAdd
[static] The SFSBuddyEvent.BUDDY_ADD constant defines the value of the type property of the event object for a buddyAdd event.
SFSBuddyEvent
  BUDDY_BLOCK : String = buddyBlock
[static] The SFSBuddyEvent.BUDDY_BLOCK constant defines the value of the type property of the event object for a buddyBlock event.
SFSBuddyEvent
  BUDDY_ERROR : String = buddyError
[static] The SFSBuddyEvent.BUDDY_ERROR constant defines the value of the type property of the event object for a buddyError event.
SFSBuddyEvent
  BUDDY_LIST_INIT : String = buddyListInit
[static] The SFSBuddyEvent.BUDDY_LIST_INIT constant defines the value of the type property of the event object for a buddyListInit event.
SFSBuddyEvent
  BUDDY_MESSAGE : String = buddyMessage
[static] The SFSBuddyEvent.BUDDY_MESSAGE constant defines the value of the type property of the event object for a buddyMessage event.
SFSBuddyEvent
  BUDDY_ONLINE_STATE_UPDATE : String = buddyOnlineStateChange
[static] The SFSBuddyEvent.BUDDY_ONLINE_STATE_UPDATE constant defines the value of the type property of the event object for a buddyOnlineStateChange event.
SFSBuddyEvent
  BUDDY_REMOVE : String = buddyRemove
[static] The SFSBuddyEvent.BUDDY_REMOVE constant defines the value of the type property of the event object for a buddyRemove event.
SFSBuddyEvent
  BUDDY_VARIABLES_UPDATE : String = buddyVariablesUpdate
[static] The SFSBuddyEvent.BUDDY_VARIABLES_UPDATE constant defines the value of the type property of the event object for a buddyVariablesUpdate event.
SFSBuddyEvent
Constructor Detail
SFSBuddyEvent()Constructor
public function SFSBuddyEvent(type:String, params:Object)

Creates a new SFSBuddyEvent instance.

Parameters
type:String — The type of event.
 
params:Object — An object containing the parameters of the event.
Method Detail
clone()method
override public function clone():Event

Duplicates the instance of the SFSBuddyEvent object.

Returns
Event — A new SFSBuddyEvent object that is identical to the original.
toString()method 
override public function toString():String

Generates a string containing all the properties of the SFSBuddyEvent object.

Returns
String — A string containing all the properties of the SFSBuddyEvent object.
Constant Detail
BUDDY_ADDConstant
public static const BUDDY_ADD:String = buddyAdd

The SFSBuddyEvent.BUDDY_ADD constant defines the value of the type property of the event object for a buddyAdd event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
buddyBuddyThe Buddy object corresponding to the buddy that was added.

See also


Example
The following example handles the possible events caused by a request to add a buddy:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSBuddyEvent.BUDDY_ADD, onBuddyAdded);
             sfs.addEventListener(SFSBuddyEvent.BUDDY_ERROR, onBuddyError);
             
             // Add user "Jack" as a new buddy to my buddies list
             sfs.send(new AddBuddyRequest("Jack"));
         }
         
         private function onBuddyAdded(evt:SFSBuddyEvent):void
         {
             trace("This buddy was added:", evt.params.buddy.name);
         }
         
         private function onBuddyError(evt:SFSBuddyEvent):void
         {
             trace("The following error occurred during a buddy-related request:", evt.params.errorMessage);
         }
         
BUDDY_BLOCKConstant 
public static const BUDDY_BLOCK:String = buddyBlock

The SFSBuddyEvent.BUDDY_BLOCK constant defines the value of the type property of the event object for a buddyBlock event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
buddyBuddyThe Buddy object corresponding to the buddy that was blocked/unblocked.

See also


Example
The following example handles the possible events caused by a request to block a buddy:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSBuddyEvent.BUDDY_BLOCK, onBuddyBlock);
             sfs.addEventListener(SFSBuddyEvent.BUDDY_ERROR, onBuddyError);
             
             // Block user "Jack" in my buddies list
             smartFox.send(new BlockBuddyRequest("Jack", true));
         }
         
         private function onBuddyBlock(evt:SFSBuddyEvent):void
         {
             var isBlocked:Boolean = evt.params.buddy.isBlocked;
             trace("Buddy " + evt.params.buddy.name + " is now " + (isBlocked ? "blocked" : "unblocked"));
         }
         
         private function onBuddyError(evt:SFSBuddyEvent):void
         {
             trace("The following error occurred while executing a buddy-related request:", evt.params.errorMessage);
         }
         
BUDDY_ERRORConstant 
public static const BUDDY_ERROR:String = buddyError

The SFSBuddyEvent.BUDDY_ERROR constant defines the value of the type property of the event object for a buddyError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringThe message which describes the error.
errorCodeintThe error code.

See also


Example
See the example provided in the BUDDY_ADD constant description.
BUDDY_LIST_INITConstant 
public static const BUDDY_LIST_INIT:String = buddyListInit

The SFSBuddyEvent.BUDDY_LIST_INIT constant defines the value of the type property of the event object for a buddyListInit event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
buddyListArrayA list of Buddy objects representing all the buddies in the current user's buddies list.
myVariablesArrayA list of all the Buddy Variables associated with the current user.

See also


Example
The following example initializes the Buddy List system:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSBuddyEvent.BUDDY_LIST_INIT, onBuddyListInitialized);
             sfs.addEventListener(SFSBuddyEvent.BUDDY_ERROR, onBuddyError)
             
             // Initialize the Buddy List system
             sfs.send(new InitBuddyListRequest());
         }
         
         private function onBuddyListInitialized(evt:SFSBuddyEvent):void
         {
             trace("Buddy List system initialized successfully");
             
             // Retrieve my buddies list
             var buddies:Array = evt.params.buddyList;
             
             // Display the online buddies in a list component in the application interface
             ...
         }
         
         private function onBuddyError(evt:SFSBuddyEvent):void
         {
             trace("The following error occurred while executing a buddy-related request:", evt.params.errorMessage);
         }
         
BUDDY_MESSAGEConstant 
public static const BUDDY_MESSAGE:String = buddyMessage

The SFSBuddyEvent.BUDDY_MESSAGE constant defines the value of the type property of the event object for a buddyMessage event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
buddyBuddyThe Buddy object representing the message sender. If the isItMe parameter is true, the value of this parameter is null (because a user is not buddy to himself).
isItMeBooleantrue if the message sender is the current user himself (in this case this event is a sort of message delivery confirmation).
messageStringThe message text.
dataISFSObjectAn instance of SFSObject containing additional custom parameters (e.g. the message color, an emoticon id, etc).


Example
The following example sends a message to a buddy and handles the related event:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSBuddyEvent.BUDDY_MESSAGE, onBuddyMessage);
             
             // Get the recipient of the message, in this case my buddy Jack
             var buddy:Buddy = sfs.buddyManager.getBuddyByName("Jack");
             
             // Send a message to Jack
             sfs.send(new BuddyMessageRequest("Hello Jack!", buddy));
         }
         
         private function onBuddyMessage(evt:SFSBuddyEvent):void
         {
             // As messages are forwarded to the sender too,
             // I have to check if I am the sender
             
             var isItMe:Boolean = evt.params.isItMe;
             var sender:Buddy = evt.params.buddy;
             
             if (isItMe)
                 trace("I said:", evt.params.message);
             else
                 trace("My buddy " + sender.name + " said:", evt.params.message);
         }
         
BUDDY_ONLINE_STATE_UPDATEConstant 
public static const BUDDY_ONLINE_STATE_UPDATE:String = buddyOnlineStateChange

The SFSBuddyEvent.BUDDY_ONLINE_STATE_UPDATE constant defines the value of the type property of the event object for a buddyOnlineStateChange event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
buddyBuddyThe Buddy object representing the buddy who changed his own online state. If the isItMe parameter is true, the value of this parameter is null (because a user is not buddy to himself).
isItMeBooleantrue if the online state was changed by the current user himself (in this case this event is a sort of state change confirmation).


Example
The following example changes the online state of the user in the Buddy List system:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSBuddyEvent.BUDDY_ONLINE_STATE_UPDATE, onBuddyOnlineStateUpdated);
             
             // Put myself offline in the Buddy List system
             sfs.send(new GoOnlineRequest(false));
         }
         
         private function onBuddyOnlineStateUpdated(evt:SFSBuddyEvent):void
         {
             // As the state change event is dispatched to me too,
             // I have to check if I am the one who changed his state
             
             var isItMe:Boolean = evt.params.isItMe;
             
             if (isItMe)
                 trace("I'm now", (sfs.buddyManager.myOnlineState ? "online" : "offline"));
             else
                 trace("My buddy " + evt.params.buddy.name + " is now", (evt.params.buddy.isOnline ? "online" : "offline"));
         }
         
BUDDY_REMOVEConstant 
public static const BUDDY_REMOVE:String = buddyRemove

The SFSBuddyEvent.BUDDY_REMOVE constant defines the value of the type property of the event object for a buddyRemove event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
buddyBuddyThe Buddy object corresponding to the buddy that was removed.

See also


Example
The following example handles the possible events caused by a request to remove a buddy:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSBuddyEvent.BUDDY_REMOVE, onBuddyRemoved);
             sfs.addEventListener(SFSBuddyEvent.BUDDY_ERROR, onBuddyError);
             
             // Remove Jack from my buddies list
             sfs.send(new RemoveBuddyRequest("Jack"));
         }
         
         private function onBuddyRemoved(evt:SFSBuddyEvent):void
         {
             trace("This buddy was removed:", evt.params.buddy.name);
         }
         
         private function onBuddyError(evt:SFSBuddyEvent):void
         {
             trace("The following error occurred while executing a buddy-related request:", evt.params.errorMessage);
         }
         
BUDDY_VARIABLES_UPDATEConstant 
public static const BUDDY_VARIABLES_UPDATE:String = buddyVariablesUpdate

The SFSBuddyEvent.BUDDY_VARIABLES_UPDATE constant defines the value of the type property of the event object for a buddyVariablesUpdate event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
buddyBuddyThe Buddy object representing the buddy who updated his own Buddy Variables. If the isItMe parameter is true, the value of this parameter is null (because a user is not buddy to himself).
isItMeBooleantrue if the Buddy Variables were updated by the current user himself (in this case this event is a sort of update confirmation).
changedVarsArrayThe list of names of the Buddy Variables that were changed (or created for the first time).


Example
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());
                 }
             }
         }