| Package | com.smartfoxserver.v2.core |
| Class | public class SFSBuddyEvent |
| Inheritance | SFSBuddyEvent BaseEvent flash.events.Event |
The SFSBuddyEvent parent class provides a public property called params which contains specific parameters depending on the event type.
See also
| Method | Defined 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 | ||
| Constant | Defined 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 | ||
| SFSBuddyEvent | () | Constructor |
public function SFSBuddyEvent(type:String, params:Object)Creates a new SFSBuddyEvent instance.
Parameterstype:String — The type of event.
| |
params:Object — An object containing the parameters of the event.
|
| clone | () | method |
override public function clone():EventDuplicates the instance of the SFSBuddyEvent object.
ReturnsEvent — A new SFSBuddyEvent object that is identical to the original.
|
| toString | () | method |
override public function toString():StringGenerates a string containing all the properties of the SFSBuddyEvent object.
ReturnsString — A string containing all the properties of the SFSBuddyEvent object.
|
| BUDDY_ADD | Constant |
public static const BUDDY_ADD:String = buddyAddThe 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:
| Property | Type | Description |
|---|---|---|
| buddy | Buddy | The Buddy object corresponding to the buddy that was added. |
See also
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_BLOCK | Constant |
public static const BUDDY_BLOCK:String = buddyBlockThe 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:
| Property | Type | Description |
|---|---|---|
| buddy | Buddy | The Buddy object corresponding to the buddy that was blocked/unblocked. |
See also
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_ERROR | Constant |
public static const BUDDY_ERROR:String = buddyErrorThe 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:
| Property | Type | Description |
|---|---|---|
| errorMessage | String | The message which describes the error. |
| errorCode | int | The error code. |
See also
| BUDDY_LIST_INIT | Constant |
public static const BUDDY_LIST_INIT:String = buddyListInitThe 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:
| Property | Type | Description |
|---|---|---|
| buddyList | Array | A list of Buddy objects representing all the buddies in the current user's buddies list. |
| myVariables | Array | A list of all the Buddy Variables associated with the current user. |
See also
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_MESSAGE | Constant |
public static const BUDDY_MESSAGE:String = buddyMessageThe 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:
| Property | Type | Description |
|---|---|---|
| buddy | Buddy | The 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). |
| isItMe | Boolean | true if the message sender is the current user himself (in this case this event is a sort of message delivery confirmation). |
| message | String | The message text. |
| data | ISFSObject | An instance of SFSObject containing additional custom parameters (e.g. the message color, an emoticon id, etc). |
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_UPDATE | Constant |
public static const BUDDY_ONLINE_STATE_UPDATE:String = buddyOnlineStateChangeThe 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:
| Property | Type | Description |
|---|---|---|
| buddy | Buddy | The 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). |
| isItMe | Boolean | true if the online state was changed by the current user himself (in this case this event is a sort of state change confirmation). |
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_REMOVE | Constant |
public static const BUDDY_REMOVE:String = buddyRemoveThe 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:
| Property | Type | Description |
|---|---|---|
| buddy | Buddy | The Buddy object corresponding to the buddy that was removed. |
See also
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_UPDATE | Constant |
public static const BUDDY_VARIABLES_UPDATE:String = buddyVariablesUpdateThe 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:
| Property | Type | Description |
|---|---|---|
| buddy | Buddy | The 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). |
| isItMe | Boolean | true if the Buddy Variables were updated by the current user himself (in this case this event is a sort of update confirmation). |
| changedVars | Array | The list of names of the Buddy Variables that were changed (or created for the first time). |
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());
}
}
}