Packagecom.smartfoxserver.v2.core
Classpublic class SFSEvent
InheritanceSFSEvent Inheritance BaseEvent Inheritance flash.events.Event

SFSEvent is the class representing most of the events dispatched by the SmartFoxServer 2X ActionScript 3 API.

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

View the examples

See also

SFSBuddyEvent


Public Properties
 PropertyDefined By
 Inheritedparams : Object
Specifies the object containing the parameters of the event.
BaseEvent
Public Methods
 MethodDefined By
  
SFSEvent(type:String, params:Object)
Creates a new SFSEvent instance.
SFSEvent
  
clone():Event
[override] Duplicates the instance of the SFSEvent object.
SFSEvent
  
toString():String
[override] Generates a string containing all the properties of the SFSEvent object.
SFSEvent
Public Constants
 ConstantDefined By
  ADMIN_MESSAGE : String = adminMessage
[static] The SFSEvent.ADMIN_MESSAGE constant defines the value of the type property of the event object for a adminMessage event.
SFSEvent
  CONFIG_LOAD_FAILURE : String = configLoadFailure
[static] The SFSEvent.CONFIG_LOAD_FAILURE constant defines the value of the type property of the event object for a configLoadFailure event.
SFSEvent
  CONFIG_LOAD_SUCCESS : String = configLoadSuccess
[static] The SFSEvent.CONFIG_LOAD_SUCCESS constant defines the value of the type property of the event object for a configLoadSuccess event.
SFSEvent
  CONNECTION : String = connection
[static] The SFSEvent.CONNECTION constant defines the value of the type property of the event object for a connection event.
SFSEvent
  CONNECTION_ATTEMPT_HTTP : String = connectionAttemptHttp
[static] The SFSEvent.CONNECTION_ATTEMPT_HTTP constant defines the value of the type property of the event object for a connectionAttemptHttp event.
SFSEvent
  CONNECTION_LOST : String = connectionLost
[static] The SFSEvent.CONNECTION_LOST constant defines the value of the type property of the event object for a connectionLost event.
SFSEvent
  CONNECTION_RESUME : String = connectionResume
[static] The SFSEvent.CONNECTION_RESUME constant defines the value of the type property of the event object for a connectionResume event.
SFSEvent
  CONNECTION_RETRY : String = connectionRetry
[static] The SFSEvent.CONNECTION_RETRY constant defines the value of the type property of the event object for a connectionRetry event.
SFSEvent
  CRYPTO_INIT : String = cryptoInit
[static] The SFSEvent.CRYPTO_INIT constant defines the value of the type property of the event object for a cryptoInit call.
SFSEvent
  EXTENSION_RESPONSE : String = extensionResponse
[static] The SFSEvent.EXTENSION_RESPONSE constant defines the value of the type property of the event object for a extensionResponse event.
SFSEvent
  INVITATION : String = invitation
[static] The SFSEvent.INVITATION constant defines the value of the type property of the event object for a invitation event.
SFSEvent
  INVITATION_REPLY : String = invitationReply
[static] The SFSEvent.INVITATION_REPLY constant defines the value of the type property of the event object for a invitationReply event.
SFSEvent
  INVITATION_REPLY_ERROR : String = invitationReplyError
[static] The SFSEvent.INVITATION_REPLY_ERROR constant defines the value of the type property of the event object for a invitationReplyError event.
SFSEvent
  LOGIN : String = login
[static] The SFSEvent.LOGIN constant defines the value of the type property of the event object for a login event.
SFSEvent
  LOGIN_ERROR : String = loginError
[static] The SFSEvent.LOGIN_ERROR constant defines the value of the type property of the event object for a loginError event.
SFSEvent
  LOGOUT : String = logout
[static] The SFSEvent.LOGOUT constant defines the value of the type property of the event object for a logout event.
SFSEvent
  MMOITEM_VARIABLES_UPDATE : String = mmoItemVariablesUpdate
[static] The SFSEvent.MMOITEM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a mmoItemVariablesUpdate event.
SFSEvent
  MODERATOR_MESSAGE : String = moderatorMessage
[static] The SFSEvent.MODERATOR_MESSAGE constant defines the value of the type property of the event object for a moderatorMessage event.
SFSEvent
  OBJECT_MESSAGE : String = objectMessage
[static] The SFSEvent.OBJECT_MESSAGE constant defines the value of the type property of the event object for a objectMessage event.
SFSEvent
  PING_PONG : String = pingPong
[static] The SFSEvent.PING_PONG constant defines the value of the type property of the event object for a pingPong event.
SFSEvent
  PLAYER_TO_SPECTATOR : String = playerToSpectator
[static] The SFSEvent.PLAYER_TO_SPECTATOR constant defines the value of the type property of the event object for a playerToSpectator event.
SFSEvent
  PLAYER_TO_SPECTATOR_ERROR : String = playerToSpectatorError
[static] The SFSEvent.PLAYER_TO_SPECTATOR_ERROR constant defines the value of the type property of the event object for a playerToSpectatorError event.
SFSEvent
  PRIVATE_MESSAGE : String = privateMessage
[static] The SFSEvent.PRIVATE_MESSAGE constant defines the value of the type property of the event object for a privateMessage event.
SFSEvent
  PROXIMITY_LIST_UPDATE : String = proximityListUpdate
[static] The SFSEvent.PROXIMITY_LIST_UPDATE constant defines the value of the type property of the event object for a proximityListUpdate event.
SFSEvent
  PUBLIC_MESSAGE : String = publicMessage
[static] The SFSEvent.PUBLIC_MESSAGE constant defines the value of the type property of the event object for a publicMessage event.
SFSEvent
  ROOM_ADD : String = roomAdd
[static] The SFSEvent.ROOM_ADD constant defines the value of the type property of the event object for a roomAdd event.
SFSEvent
  ROOM_CAPACITY_CHANGE : String = roomCapacityChange
[static] The SFSEvent.ROOM_CAPACITY_CHANGE constant defines the value of the type property of the event object for a roomCapacityChange event.
SFSEvent
  ROOM_CAPACITY_CHANGE_ERROR : String = roomCapacityChangeError
[static] The SFSEvent.ROOM_CAPACITY_CHANGE_ERROR constant defines the value of the type property of the event object for a roomCapacityChangeError event.
SFSEvent
  ROOM_CREATION_ERROR : String = roomCreationError
[static] The SFSEvent.ROOM_CREATION_ERROR constant defines the value of the type property of the event object for a roomCreationError event.
SFSEvent
  ROOM_FIND_RESULT : String = roomFindResult
[static] The SFSEvent.ROOM_FIND_RESULT constant defines the value of the type property of the event object for a roomFindResult event.
SFSEvent
  ROOM_GROUP_SUBSCRIBE : String = roomGroupSubscribe
[static] The SFSEvent.ROOM_GROUP_SUBSCRIBE constant defines the value of the type property of the event object for a roomGroupSubscribe event.
SFSEvent
  ROOM_GROUP_SUBSCRIBE_ERROR : String = roomGroupSubscribeError
[static] The SFSEvent.ROOM_GROUP_SUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupSubscribeError event.
SFSEvent
  ROOM_GROUP_UNSUBSCRIBE : String = roomGroupUnsubscribe
[static] The SFSEvent.ROOM_GROUP_UNSUBSCRIBE constant defines the value of the type property of the event object for a roomGroupUnsubscribe event.
SFSEvent
  ROOM_GROUP_UNSUBSCRIBE_ERROR : String = roomGroupUnsubscribeError
[static] The SFSEvent.ROOM_GROUP_UNSUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupUnsubscribeError event.
SFSEvent
  ROOM_JOIN : String = roomJoin
[static] The SFSEvent.ROOM_JOIN constant defines the value of the type property of the event object for a roomJoin event.
SFSEvent
  ROOM_JOIN_ERROR : String = roomJoinError
[static] The SFSEvent.ROOM_JOIN_ERROR constant defines the value of the type property of the event object for a roomJoinError event.
SFSEvent
  ROOM_NAME_CHANGE : String = roomNameChange
[static] The SFSEvent.ROOM_NAME_CHANGE constant defines the value of the type property of the event object for a roomNameChange event.
SFSEvent
  ROOM_NAME_CHANGE_ERROR : String = roomNameChangeError
[static] The SFSEvent.ROOM_NAME_CHANGE_ERROR constant defines the value of the type property of the event object for a roomNameChangeError event.
SFSEvent
  ROOM_PASSWORD_STATE_CHANGE : String = roomPasswordStateChange
[static] The SFSEvent.ROOM_PASSWORD_STATE_CHANGE constant defines the value of the type property of the event object for a roomPasswordStateChange event.
SFSEvent
  ROOM_PASSWORD_STATE_CHANGE_ERROR : String = roomPasswordStateChangeError
[static] The SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR constant defines the value of the type property of the event object for a roomPasswordStateChangeError event.
SFSEvent
  ROOM_REMOVE : String = roomRemove
[static] The SFSEvent.ROOM_REMOVE constant defines the value of the type property of the event object for a roomRemove event.
SFSEvent
  ROOM_VARIABLES_UPDATE : String = roomVariablesUpdate
[static] The SFSEvent.ROOM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a roomVariablesUpdate event.
SFSEvent
  SOCKET_ERROR : String = socketError
[static] The SFSEvent.SOCKET_ERROR constant defines the value of the type property of the event object for a socketError event.
SFSEvent
  SPECTATOR_TO_PLAYER : String = spectatorToPlayer
[static] The SFSEvent.SPECTATOR_TO_PLAYER constant defines the value of the type property of the event object for a spectatorToPlayer event.
SFSEvent
  SPECTATOR_TO_PLAYER_ERROR : String = spectatorToPlayerError
[static] The SFSEvent.SPECTATOR_TO_PLAYER_ERROR constant defines the value of the type property of the event object for a spectatorToPlayerError event.
SFSEvent
  UDP_INIT : String = udpInit
[static] The SFSEvent.UDP_INIT constant defines the value of the type property of the event object for a udpInit event.
SFSEvent
  USER_COUNT_CHANGE : String = userCountChange
[static] The SFSEvent.USER_COUNT_CHANGE constant defines the value of the type property of the event object for a userCountChange event.
SFSEvent
  USER_ENTER_ROOM : String = userEnterRoom
[static] The SFSEvent.USER_ENTER_ROOM constant defines the value of the type property of the event object for a userEnterRoom event.
SFSEvent
  USER_EXIT_ROOM : String = userExitRoom
[static] The SFSEvent.USER_EXIT_ROOM constant defines the value of the type property of the event object for a userExitRoom event.
SFSEvent
  USER_FIND_RESULT : String = userFindResult
[static] The SFSEvent.USER_FIND_RESULT constant defines the value of the type property of the event object for a userFindResult event.
SFSEvent
  USER_VARIABLES_UPDATE : String = userVariablesUpdate
[static] The SFSEvent.USER_VARIABLES_UPDATE constant defines the value of the type property of the event object for a userVariablesUpdate event.
SFSEvent
Constructor Detail
SFSEvent()Constructor
public function SFSEvent(type:String, params:Object)

Creates a new SFSEvent 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 SFSEvent object.

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

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

Returns
String — A string containing all the properties of the SFSEvent object.
Constant Detail
ADMIN_MESSAGEConstant
public static const ADMIN_MESSAGE:String = adminMessage

The SFSEvent.ADMIN_MESSAGE constant defines the value of the type property of the event object for a adminMessage event.

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

PropertyTypeDescription
senderUserAn object representing the administrator user who sent the message.
messageStringThe message sent by the administrator.
dataISFSObjectAn object containing custom parameters which might accompany the message.

See also


Example
The following example sends an administration message to all the users in the Zone; it also shows how to handle the related event:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ADMIN_MESSAGE, onAdminMessage);
             
             // Set the message recipients: all users in the Zone
             var recipMode:MessageRecipientMode = new MessageRecipientMode(MessageRecipientMode.TO_ZONE, null);
             
             // Send the administrator message
             sfs.send(new AdminMessageRequest("Hello to everybody from the Administrator!", recipMode));
         }
         
         private function onAdminMessage(evt:SFSEvent):void
         {
             trace("The administrator sent the following message: " + evt.params.message);
         }
         
CONFIG_LOAD_FAILUREConstant 
public static const CONFIG_LOAD_FAILURE:String = configLoadFailure

The SFSEvent.CONFIG_LOAD_FAILURE constant defines the value of the type property of the event object for a configLoadFailure event.

No parameters are available for this event object.

See also


Example
See the example provided in the CONFIG_LOAD_SUCCESS constant description.
CONFIG_LOAD_SUCCESSConstant 
public static const CONFIG_LOAD_SUCCESS:String = configLoadSuccess

The SFSEvent.CONFIG_LOAD_SUCCESS constant defines the value of the type property of the event object for a configLoadSuccess event.

No parameters are available for this event object.

See also


Example
The following example loads an external configuration file:
         
         private function someMethod():void
         {
             var sfs:SmartFox = new SmartFox();
             
             sfs.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, onConfigLoaded);
             sfs.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, onConfigLoadFailed);
             
             sfs.loadConfig("testConfig.xml", false);
         }
         
         private function onConfigLoaded(evt:SFSEvent):void
         {
             // Configuration loaded successfully, now connect
             sfs.connect();
         }
         
         private function onConfigLoadFailed(evt:SFSEvent):void
         {
             trace("Failed loading configuration file");
         }
         
CONNECTIONConstant 
public static const CONNECTION:String = connection

The SFSEvent.CONNECTION constant defines the value of the type property of the event object for a connection event.

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

PropertyTypeDescription
successBooleanThe connection result: true if a connection was established, false otherwise.

See also


Example
The following example starts a connection:
         
         private function someMethod():void
         {
             var sfs:SmartFox = new SmartFox();
             sfs.addEventListener(SFSEvent.CONNECTION, onConnection);
             
             sfs.connect();
         }
         
         private function onConnection(evt:SFSEvent):void
         {
             if (evt.params.success)
                 trace("Connection established");
             else
                 trace("Connection failed");
         }
         
CONNECTION_ATTEMPT_HTTPConstant 
public static const CONNECTION_ATTEMPT_HTTP:String = connectionAttemptHttp

The SFSEvent.CONNECTION_ATTEMPT_HTTP constant defines the value of the type property of the event object for a connectionAttemptHttp event.

No parameters are available for this event object.

See also


Example
See the example provided in the CONNECTION_ATTEMPT_HTTP constant description.
CONNECTION_LOSTConstant 
public static const CONNECTION_LOST:String = connectionLost

The SFSEvent.CONNECTION_LOST constant defines the value of the type property of the event object for a connectionLost event.

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

PropertyTypeDescription
reasonStringThe reason of the disconnection, among those available in the ClientDisconnectionReason class.

See also


Example
The following example handles a disconnection event:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.CONNECTION_LOST, onConnectionLost);
         }
         
         private function onConnectionLost(evt:SFSEvent):void
         {
             var reason:String = evt.params.reason;
             
             if (reason != ClientDisconnectionReason.MANUAL)
             {
                 if (reason == ClientDisconnectionReason.IDLE)
                     trace("A disconnection occurred due to inactivity");
                 else if (reason == ClientDisconnectionReason.KICK)
                     trace("You have been kicked by the moderator");
                 else if (reason == ClientDisconnectionReason.BAN)
                     trace("You have been banned by the moderator");
                 else
                     trace("A disconnection occurred due to unknown reason; please check the server log");
             }
             else
             {
                 // Manual disconnection is usually ignored
             }
         }
         
CONNECTION_RESUMEConstant 
public static const CONNECTION_RESUME:String = connectionResume

The SFSEvent.CONNECTION_RESUME constant defines the value of the type property of the event object for a connectionResume event.

No parameters are available for this event object.

See also


Example
See the example provided in the CONNECTION_RETRY constant description.
CONNECTION_RETRYConstant 
public static const CONNECTION_RETRY:String = connectionRetry

The SFSEvent.CONNECTION_RETRY constant defines the value of the type property of the event object for a connectionRetry event.

No parameters are available for this event object.

See also


Example
The following example handles a temporary disconnection event and the following connection resuming:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.CONNECTION_RETRY, onConnectionRetry);
             sfs.addEventListener(SFSEvent.CONNECTION_RESUME, onConnectionResumed);
             sfs.addEventListener(SFSEvent.CONNECTION_LOST, onConnectionLost);
         }
         
         private function onConnectionRetry(evt:SFSEvent):void
         {
             // Freeze the GUI and provide some feedback to the player
             ...
         }
         
         private function onConnectionResumed(evt:SFSEvent):void
         {
             // Unfreeze the GUI and let the player continue with the game
             ...
         }
         
         private function onConnectionLost(evt:SFSEvent):void
         {
             trace("Ouch, connection was lost. Reason: " + evt.params.reason);
         }
         
CRYPTO_INITConstant 
public static const CRYPTO_INIT:String = cryptoInit

The SFSEvent.CRYPTO_INIT constant defines the value of the type property of the event object for a cryptoInit call.

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

PropertyTypeDescription
successBooleantrue if a unique encryption key was successfully retrieved via HTTPS, false if the transaction failed.
errorMsgStringIf success is false, provides additional details on the occurred error.


Example
The following example initializes the socket cryptography. Always makes sure to initialize cryptography right after having connected.
         var sfs:SmartFox = new SmartFox();
         sfs.addEventListener(SFSEvent.CONNECTION, onConnect);
         sfs.addEventListener(SFSEvent.CRYPTO_INIT, onCryptInit);
         
         sfs.connect("mysecuredomain.com", 9933);
         
         function onConnect(evt:SFSEvent):void
         {
             if (evt.param.success)
                 sfs.initCrypto();
                 
             else
                 trace("Sorry, connection failed");
         }
         
         function onCryptInit(evt:SFSEvent):void
         {
             ta_data.text = evt.params.success;
             
             if (evt.params.success)
                 sfs.send(new LoginRequest("MyName", "MyPassword", "MyZone"));
         
             else
                 trace("Crypto init failed. Caused by: " + evt.params.errorMsg)
         }
         
EXTENSION_RESPONSEConstant 
public static const EXTENSION_RESPONSE:String = extensionResponse

The SFSEvent.EXTENSION_RESPONSE constant defines the value of the type property of the event object for a extensionResponse event.

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

PropertyTypeDescription
cmdStringThe name of the command which identifies an action that should be executed by the client. If this event is fired in response to a request sent by the client, it is a common practice to use the same command name passed to the request also in the response.
paramsISFSObjectAn object containing custom data sent by the Extension.
sourceRoomNumber[DEPRECATED - Use room property] The id of the Room which the Extension is attached to (for Room Extensions only).
roomRoomAn object representing the Room which the Extension is attached to (for Room Extensions only).
packetIdNumberThe id of the packet when the UDP protocol is used. As this is an auto-increment value generated by the server, it can be useful to detect UDP packets received in the wrong order.


Example
The following example sends a command to the Zone Extension; it also handles responses coming from the Extension by implementing the extensionResponse listener (the same command name is used in both the request and the response):
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, onExtensionResponse);
             
             // Send two integers to the Zone extension and get their sum in return
             var params:ISFSObject = new SFSObject();
             params.putInt("n1", 26);
             params.putInt("n2", 16);
             
             sfs.send(new ExtensionRequest("add", params));
         }
         
         private function onExtensionResponse(evt:SFSEvent):void
         {
             if (evt.params.cmd == "add")
             {
                 var responseParams:ISFSObject = evt.params.params as SFSObject;
                 
                 // We expect an int parameter called "sum"
                 trace("The sum is: " + responseParams.getInt("sum"));
             }
         }
         
INVITATIONConstant 
public static const INVITATION:String = invitation

The SFSEvent.INVITATION constant defines the value of the type property of the event object for a invitation event.

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

PropertyTypeDescription
invitationInvitationAn object representing the invitation received by the current user.

See also


Example
The following example receives an invitation and accepts it automatically; in a real case scenario, the application interface usually allows the user choosing to accept or refuse the invitation, or even ignore it:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.INVITATION, onInvitationReceived);
             sfs.addEventListener(SFSEvent.INVITATION_REPLY_ERROR, onInvitationReplyError);
         }
         
         private function onInvitationReceived(evt:SFSEvent):void
         {
             // Let's accept this invitation            
             sfs.send(new InvitationReplyRequest(evt.params.invitation, InvitationReply.ACCEPT));
         }
         
         private function onInvitationReplyError(evt:SFSEvent):void
         {
             trace("Failed to reply to invitation due to the following problem: " + evt.params.errorMessage);
         }
         
INVITATION_REPLYConstant 
public static const INVITATION_REPLY:String = invitationReply

The SFSEvent.INVITATION_REPLY constant defines the value of the type property of the event object for a invitationReply event.

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

PropertyTypeDescription
inviteeUserAn object representing the user who replied to the invitation.
replyintThe answer to the invitation among those available as constants in the InvitationReply class.
dataISFSObjectAn object containing custom parameters, for example a message describing the reason of refusal.

See also


Example
See the example provided in the INVITATION constant description.
INVITATION_REPLY_ERRORConstant 
public static const INVITATION_REPLY_ERROR:String = invitationReplyError

The SFSEvent.INVITATION_REPLY_ERROR constant defines the value of the type property of the event object for a invitationReplyError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the INVITATION constant description.
LOGINConstant 
public static const LOGIN:String = login

The SFSEvent.LOGIN constant defines the value of the type property of the event object for a login event.

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

PropertyTypeDescription
userUserAn object representing the user who performed the login.
dataISFSObjectAn object containing custom parameters returned by a custom login system, if any.

See also


Example
The following example performs a login in the "SimpleChat" Zone:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.LOGIN, onLogin);
             sfs.addEventListener(SFSEvent.LOGIN_ERROR, onLoginError);
             
             // Login
             sfs.send(new LoginRequest("FozzieTheBear", "", "SimpleChat"));
         }
         
         private function onLogin(evt:SFSEvent):void
         {
             trace("Login successful!");
         }
         
         private function onLoginError(evt:SFSEvent):void
         {
             trace("Login failure: " + evt.params.errorMessage);
         }
         
LOGIN_ERRORConstant 
public static const LOGIN_ERROR:String = loginError

The SFSEvent.LOGIN_ERROR constant defines the value of the type property of the event object for a loginError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the LOGIN constant description.
LOGOUTConstant 
public static const LOGOUT:String = logout

The SFSEvent.LOGOUT constant defines the value of the type property of the event object for a logout event.

No parameters are available for this event object.

See also


Example
The following example performs a logout from the current Zone:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.LOGOUT, onLogout);
             
             // Logout
             sfs.send(new LogoutRequest());
         }
         
         private function onLogout(evt:SFSEvent):void
         {
             trace("Logout executed!");
         }
         
MMOITEM_VARIABLES_UPDATEConstant 
public static const MMOITEM_VARIABLES_UPDATE:String = mmoItemVariablesUpdate

The SFSEvent.MMOITEM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a mmoItemVariablesUpdate event.

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

PropertyTypeDescription
roomMMORoomThe MMORoom where the MMOItem whose Variables have been updated is located.
mmoItemMMOItemThe MMOItem whose variables have been updated.
changedVarsArrayThe list of names of the MMOItem Variables that were changed (or created for the first time).


Example
The following example shows how to handle the MMOItem Variable update:
                  private function onMMOItemVarsUpdate(evt:SFSEvent):void
         {
             var changedVars:Array = evt.params.changedVars;
             var item:IMMOItem = evt.params.mmoItem;
             
             // Check if the MMOItem was moved 
             if (changedVars.indexOf("x") != -1 || changedVars.indexOf("y") != -1)
             {
                 // Move the sprite representing the MMOItem on the stage
                 ...
             }
         }
         
MODERATOR_MESSAGEConstant 
public static const MODERATOR_MESSAGE:String = moderatorMessage

The SFSEvent.MODERATOR_MESSAGE constant defines the value of the type property of the event object for a moderatorMessage event.

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

PropertyTypeDescription
senderUserAn object representing the moderator user who sent the message.
messageStringThe message sent by the moderator.
dataISFSObjectAn object containing custom parameters which might accompany the message.

See also


Example
The following example sends a moderator message to all the users in the last joned Room; it also shows how to handle the related event:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.MODERATOR_MESSAGE, onModeratorMessage);
             
             // Set the message recipients: all users in the current Room
             var recipMode:MessageRecipientMode = new MessageRecipientMode(MessageRecipientMode.TO_ROOM, sfs.lastJoinedRoom);
             
             // Send the moderator message
             sfs.send(new ModeratorMessageRequest("Hello everybody, I'm the Moderator!", recipMode));
         }
         
         private function onModeratorMessage(evt:SFSEvent):void
         {
             trace("The moderator sent the following message: " + evt.params.message);
         }
         
OBJECT_MESSAGEConstant 
public static const OBJECT_MESSAGE:String = objectMessage

The SFSEvent.OBJECT_MESSAGE constant defines the value of the type property of the event object for a objectMessage event.

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

PropertyTypeDescription
senderUserAn object representing the user who sent the message.
messageSFSObjectThe content of the message: an object containing the custom parameters sent by the sender.


Example
The following example sends the player's character movement coordinates and handles the respective event (note: the myCharacter instance is supposed to be the user sprite on the stage, while the getUserCharacter method retrieves the sprite of other users' characters):
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.OBJECT_MESSAGE, onObjectMessage);
             
             // Send my movement to all players
             var dataObj:ISFSObject = new SFSObject();
             dataObj.putInt("x", myCharacter.x);
             dataObj.putInt("y", myCharacter.y);
             
             sfs.send(new ObjectMessageRequest(dataObj));
         }
         
         private function onObjectMessage(evt:SFSEvent):void
         {
             var dataObj:ISFSObject = evt.params.message as SFSObject;
             
             var sender:User = evt.params.sender;
             var character:Sprite = getUserCharacter(sender.id);
             
             character.x = dataObj.getInt("x");
             character.y = dataObj.getInt("y");
         }
         
PING_PONGConstant 
public static const PING_PONG:String = pingPong

The SFSEvent.PING_PONG constant defines the value of the type property of the event object for a pingPong event.

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

PropertyTypeDescription
lagValueintThe average of the last ten measured lag values, expressed in milliseconds.

PLAYER_TO_SPECTATORConstant 
public static const PLAYER_TO_SPECTATOR:String = playerToSpectator

The SFSEvent.PLAYER_TO_SPECTATOR constant defines the value of the type property of the event object for a playerToSpectator event.

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

PropertyTypeDescription
roomRoomAn object representing the Room in which the player is turned to spectator.
userUserAn object representing the player who was turned to spectator.

See also


Example
The following example turns the current user from player to spectator in the last joined Game Room:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.PLAYER_TO_SPECTATOR, onPlayerToSpectatorSwitch);
             sfs.addEventListener(SFSEvent.PLAYER_TO_SPECTATOR_ERROR, onPlayerToSpectatorSwitchError);
             
             // Switch player to spectator
             sfs.send(new PlayerToSpectatorRequest());
         }
         
         private function onPlayerToSpectatorSwitch(evt:SFSEvent):void
         {
             trace("Player " + evt.params.user + " is now a spectator");
         }
         
         private function onPlayerToSpectatorSwitchError(evt:SFSEvent):void
         {
             trace("Unable to become a spectator due to the following error: " + evt.params.errorMessage);
         }
         
PLAYER_TO_SPECTATOR_ERRORConstant 
public static const PLAYER_TO_SPECTATOR_ERROR:String = playerToSpectatorError

The SFSEvent.PLAYER_TO_SPECTATOR_ERROR constant defines the value of the type property of the event object for a playerToSpectatorError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the PLAYER_TO_SPECTATOR constant description.
PRIVATE_MESSAGEConstant 
public static const PRIVATE_MESSAGE:String = privateMessage

The SFSEvent.PRIVATE_MESSAGE constant defines the value of the type property of the event object for a privateMessage event.

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

PropertyTypeDescription
senderUserAn object representing the user who sent the message.
messageStringThe message sent by the user.
dataISFSObjectAn object containing custom parameters which might accompany the message.

See also


Example
The following example sends a private message and handles the respective event:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.PRIVATE_MESSAGE, onPrivateMessage);
             
             // Send a private message to Jack
             var user:User = sfs.usermanager.getUserByName("Jack");
             sfs.send(new PrivateMessageRequest("Hello my friend!", user.id));
         }
         
         private function onPrivateMessage(evt:SFSEvent):void
         {
             // As messages are forwarded to the sender too,
             // I have to check if I am the sender
             
             var sender:User = evt.params.sender;
             
             if (sender != sfs.mySelf)
                 trace("User " + sender.name + " sent me this PM:", evt.params.message);
         }
         
PROXIMITY_LIST_UPDATEConstant 
public static const PROXIMITY_LIST_UPDATE:String = proximityListUpdate

The SFSEvent.PROXIMITY_LIST_UPDATE constant defines the value of the type property of the event object for a proximityListUpdate event.

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

PropertyTypeDescription
roomRoomThe Room in which the event occurred.
addedUsersArrayA list of User objects representing the users who entered the current user's Area of Interest.
removedUsersArrayA list of User objects representing the users who left the current user's Area of Interest.
addedItemsArrayA list of MMOItem objects which entered the current user's Area of Interest.
removedItemsArrayA list of MMOItem objects which left the current user's Area of Interest.


Example
The following example shows how to handle the proximity user list provided by the event in order to add new avatars on the stage and remove those who left the current user's proximity range:
         
         private function onProximityListUpdate(evt:SFSEvent):void
         {
             var added:Array = evt.params.addedUsers;
             var removed:Array = evt.params.removedUsers;
         
             // Add users that entered the proximity list
             for each (var user:User in added)
             {
                 // Obtain the coordinates at which the user "appeared" in our range
                 var entryPoint:Vec3D = user.aoiEntryPoint;
             
                 // Add new avatar on screen
                 var avatarSprite:AvatarSprite = new AvatarSprite();
                 avatarSprite.x = entryPoint.px;
                 avatarSprite.y = entryPoint.py;
                 ...
             }
         
             // Remove users that left the proximity list
             for each (var user:User in removed)
             {
                 // Remove the avatar from stage
                 ...
             }
         }
         
PUBLIC_MESSAGEConstant 
public static const PUBLIC_MESSAGE:String = publicMessage

The SFSEvent.PUBLIC_MESSAGE constant defines the value of the type property of the event object for a publicMessage event.

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

PropertyTypeDescription
roomRoomAn object representing the Room at which the message is targeted.
senderUserAn object representing the user who sent the message.
messageStringThe message sent by the user.
dataISFSObjectAn object containing custom parameters which might accompany the message.

See also


Example
The following example sends a public message and handles the respective event:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.PUBLIC_MESSAGE, onPublicMessage);
             
             // Send a public message
             sfs.send(new PublicMessageRequest("Hello everyone!"));
         }
         
         private function onPublicMessage(evt:SFSEvent):void
         {
             // As messages are forwarded to the sender too,
             // I have to check if I am the sender
             
             var sender:User = evt.params.sender;
             
             if (sender == sfs.mySelf)
                 trace("I said:", evt.params.message);
             else
                 trace("User " + sender.name + " said:", evt.params.message);
         }
         
ROOM_ADDConstant 
public static const ROOM_ADD:String = roomAdd

The SFSEvent.ROOM_ADD constant defines the value of the type property of the event object for a roomAdd event.

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

PropertyTypeDescription
roomRoomAn object representing the Room that was created.

See also


Example
The following example creates a new chat Room:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ROOM_ADD, onRoomCreated);
             sfs.addEventListener(SFSEvent.ROOM_CREATION_ERROR, onRoomCreationError);
             
             // Define the settings of a new chat Room
             var settings:RoomSettings = new RoomSettings("My Chat Room");
             settings.maxUsers = 40;
             settings.groupId = "chats";
             
             // Create the Room
             sfs.send(new CreateRoomRequest(settings));
         }
         
         private function onRoomCreated(evt:SFSEvent):void
         {
             trace("Room created: " + evt.params.room);
         }
         
         private function onRoomCreationError(evt:SFSEvent):void
         {
             trace("Room creation failure: " + evt.params.errorMessage);
         }
         
ROOM_CAPACITY_CHANGEConstant 
public static const ROOM_CAPACITY_CHANGE:String = roomCapacityChange

The SFSEvent.ROOM_CAPACITY_CHANGE constant defines the value of the type property of the event object for a roomCapacityChange event.

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

PropertyTypeDescription
roomRoomAn object representing the Room whose capacity was changed.

See also


Example
The following example changes the capacity of an existing Room:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ROOM_CAPACITY_CHANGE, onRoomCapacityChanged);
             sfs.addEventListener(SFSEvent.ROOM_CAPACITY_CHANGE_ERROR, onRoomCapacityChangeError);
             
             var theRoom:Room = sfs.getRoomByName("Gonzo's Room");
             
             // Resize the Room so that it allows a maximum of 100 users and zero spectators
             sfs.send(new ChangeRoomCapacityRequest(theRoom, 100, 0));
         }
         
         private function onRoomCapacityChanged(evt:SFSEvent):void
         {
             trace("The capacity of Room " + evt.params.room.name + " was changed successfully");
         }
         
         private function onRoomCapacityChangeError(evt:SFSEvent):void
         {
             trace("Room capacity change failed: " + evt.params.errorMessage);
         }
         
ROOM_CAPACITY_CHANGE_ERRORConstant 
public static const ROOM_CAPACITY_CHANGE_ERROR:String = roomCapacityChangeError

The SFSEvent.ROOM_CAPACITY_CHANGE_ERROR constant defines the value of the type property of the event object for a roomCapacityChangeError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the ROOM_CAPACITY_CHANGE constant description.
ROOM_CREATION_ERRORConstant 
public static const ROOM_CREATION_ERROR:String = roomCreationError

The SFSEvent.ROOM_CREATION_ERROR constant defines the value of the type property of the event object for a roomCreationError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the ROOM_ADD constant description.
ROOM_FIND_RESULTConstant 
public static const ROOM_FIND_RESULT:String = roomFindResult

The SFSEvent.ROOM_FIND_RESULT constant defines the value of the type property of the event object for a roomFindResult event.

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

PropertyTypeDescription
roomsArrayA list of Room objects representing the Rooms matching the search criteria. If no Room is found, the list is empty.


Example
The following example looks for all the server Rooms whose "country" Room Variable is set to "Sweden":
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ROOM_FIND_RESULT, onRoomFindResult);
             
             // Create a matching expression to find Rooms with a "country" variable equal to "Sweden"
             var exp:MatchExpression = new MatchExpression("country", StringMatch.EQUALS, "Sweden");
             
             // Find the Rooms
             sfs.send(new FindRoomRequest(exp));
         }
         
         private function onRoomFindResult(evt:SFSEvent):void
         {
             trace("Rooms found: " + evt.params.rooms);
         }
         
ROOM_GROUP_SUBSCRIBEConstant 
public static const ROOM_GROUP_SUBSCRIBE:String = roomGroupSubscribe

The SFSEvent.ROOM_GROUP_SUBSCRIBE constant defines the value of the type property of the event object for a roomGroupSubscribe event.

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

PropertyTypeDescription
groupIdStringThe name of the Group that was subscribed.
newRoomsArrayA list of Room objects representing the Rooms belonging to the subscribed Group.

See also


Example
The following example makes the current user subscribe a Group:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ROOM_GROUP_SUBSCRIBE, onGroupSubscribed);
             sfs.addEventListener(SFSEvent.ROOM_GROUP_SUBSCRIBE_ERROR, onGroupSubscribeError);
             
             // Subscribe the "cardGames" group
             sfs.send(new SubscribeRoomGroupRequest("cardGames"));
         }
         
         private function onGroupSubscribed(evt:SFSEvent):void
         {
             trace("Group subscribed. The following rooms are now accessible: " + evt.params.newRooms);
         }
         
         private function onGroupSubscribeError(evt:SFSEvent):void
         {
             trace("Group subscription failed: " + evt.params.errorMessage);
         }
         
ROOM_GROUP_SUBSCRIBE_ERRORConstant 
public static const ROOM_GROUP_SUBSCRIBE_ERROR:String = roomGroupSubscribeError

The SFSEvent.ROOM_GROUP_SUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupSubscribeError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the ROOM_GROUP_SUBSCRIBE constant description.
ROOM_GROUP_UNSUBSCRIBEConstant 
public static const ROOM_GROUP_UNSUBSCRIBE:String = roomGroupUnsubscribe

The SFSEvent.ROOM_GROUP_UNSUBSCRIBE constant defines the value of the type property of the event object for a roomGroupUnsubscribe event.

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

PropertyTypeDescription
groupIdStringThe name of the Group that was unsubscribed.

See also


Example
The following example makes the current user unsubscribe a Group:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ROOM_GROUP_UNSUBSCRIBE, onGroupUnsubscribed);
             sfs.addEventListener(SFSEvent.ROOM_GROUP_UNSUBSCRIBE_ERROR, onGroupUnsubscribeError);
             
             // Unsubscribe the "cardGames" group
             sfs.send(new UnsubscribeRoomGroupRequest("cardGames"));
         }
         
         private function onGroupUnsubscribed(evt:SFSEvent):void
         {
             trace("Group unsubscribed: " + evt.params.groupId);
         }
         
         private function onGroupUnsubscribeError(evt:SFSEvent):void
         {
             trace("Group unsubscribing failed: " + evt.params.errorMessage);
         }
         
ROOM_GROUP_UNSUBSCRIBE_ERRORConstant 
public static const ROOM_GROUP_UNSUBSCRIBE_ERROR:String = roomGroupUnsubscribeError

The SFSEvent.ROOM_GROUP_UNSUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupUnsubscribeError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the ROOM_GROUP_UNSUBSCRIBE constant description.
ROOM_JOINConstant 
public static const ROOM_JOIN:String = roomJoin

The SFSEvent.ROOM_JOIN constant defines the value of the type property of the event object for a roomJoin event.

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

PropertyTypeDescription
roomRoomAn object representing the Room that was joined.

See also


Example
The following example makes the user join an existing Room:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ROOM_JOIN, onRoomJoined);
             sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError);
             
             // Join a Room called "Lobby"
             sfs.send(new JoinRoomRequest("Lobby"));
         }
         
         private function onRoomJoined(evt:SFSEvent):void
         {
             trace("Room joined successfully: " + evt.params.room);
         }
         
         private function onRoomJoinError(evt:SFSEvent):void
         {
             trace("Room joining failed: " + evt.params.errorMessage);
         }
         
ROOM_JOIN_ERRORConstant 
public static const ROOM_JOIN_ERROR:String = roomJoinError

The SFSEvent.ROOM_JOIN_ERROR constant defines the value of the type property of the event object for a roomJoinError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the ROOM_JOIN constant description.
ROOM_NAME_CHANGEConstant 
public static const ROOM_NAME_CHANGE:String = roomNameChange

The SFSEvent.ROOM_NAME_CHANGE constant defines the value of the type property of the event object for a roomNameChange event.

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

PropertyTypeDescription
roomRoomAn object representing the Room which was renamed.
oldNameStringThe previous name of the Room.

See also


Example
The following example renames an existing Room:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ROOM_NAME_CHANGE, onRoomNameChanged);
             sfs.addEventListener(SFSEvent.ROOM_NAME_CHANGE_ERROR, onRoomNameChangeError);
             
             var theRoom:Room = sfs.getRoomByName("Gonzo's Room");
             sfs.send(new ChangeRoomNameRequest(theRoom, "Gonzo The Great's Room"));
         }
         
         private function onRoomNameChanged(evt:SFSEvent):void
         {
             trace("Room " + evt.params.oldName + " was successfully renamed to " + evt.params.room.name);
         }
         
         private function onRoomNameChangeError(evt:SFSEvent):void
         {
             trace("Room name change failed: " + evt.params.errorMessage);
         }
         
ROOM_NAME_CHANGE_ERRORConstant 
public static const ROOM_NAME_CHANGE_ERROR:String = roomNameChangeError

The SFSEvent.ROOM_NAME_CHANGE_ERROR constant defines the value of the type property of the event object for a roomNameChangeError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the ROOM_NAME_CHANGE constant description.
ROOM_PASSWORD_STATE_CHANGEConstant 
public static const ROOM_PASSWORD_STATE_CHANGE:String = roomPasswordStateChange

The SFSEvent.ROOM_PASSWORD_STATE_CHANGE constant defines the value of the type property of the event object for a roomPasswordStateChange event.

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

PropertyTypeDescription
roomRoomAn object representing the Room whose password was changed.

See also


Example
The following example changes the password of an existing Room:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ROOM_PASSWORD_STATE_CHANGE, onRoomPasswordStateChanged);
             sfs.addEventListener(SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR, onRoomPasswordStateChangeError);
             
             var theRoom:Room = sfs.getRoomByName("Gonzo's Room");
             sfs.send(new ChangeRoomPasswordStateRequest(theRoom, "mammamia"));
         }
         
         private function onRoomPasswordStateChanged(evt:SFSEvent):void
         {
             trace("The password of Room " + evt.params.room.name + " was changed successfully");
         }
         
         private function onRoomPasswordStateChangeError(evt:SFSEvent):void
         {
             trace("Room password change failed: " + evt.params.errorMessage);
         }
         
ROOM_PASSWORD_STATE_CHANGE_ERRORConstant 
public static const ROOM_PASSWORD_STATE_CHANGE_ERROR:String = roomPasswordStateChangeError

The SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR constant defines the value of the type property of the event object for a roomPasswordStateChangeError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the ROOM_PASSWORD_STATE_CHANGE constant description.
ROOM_REMOVEConstant 
public static const ROOM_REMOVE:String = roomRemove

The SFSEvent.ROOM_REMOVE constant defines the value of the type property of the event object for a roomRemove event.

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

PropertyTypeDescription
roomRoomAn object representing the Room that was removed.

See also


Example
The following example shows how to handle this event type:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.ROOM_REMOVE, onRoomRemoved);
         }
         
         private function onRoomRemoved(evt:SFSEvent):void
         {
             trace("The following Room was removed: " + evt.params.room);
         }
         
ROOM_VARIABLES_UPDATEConstant 
public static const ROOM_VARIABLES_UPDATE:String = roomVariablesUpdate

The SFSEvent.ROOM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a roomVariablesUpdate event.

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

PropertyTypeDescription
roomRoomAn object representing the Room where the Room Variable update occurred.
changedVarsArrayThe list of names of the Room Variables that were changed (or created for the first time).


Example
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");
             }
         }
         
SOCKET_ERRORConstant 
public static const SOCKET_ERROR:String = socketError

The SFSEvent.SOCKET_ERROR constant defines the value of the type property of the event object for a socketError event.

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

PropertyTypeDescription
errorMessageStringThe description of the error.

SPECTATOR_TO_PLAYERConstant 
public static const SPECTATOR_TO_PLAYER:String = spectatorToPlayer

The SFSEvent.SPECTATOR_TO_PLAYER constant defines the value of the type property of the event object for a spectatorToPlayer event.

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

PropertyTypeDescription
roomRoomAn object representing the Room in which the spectator is turned to player.
userUserAn object representing the spectator who was turned to player.
playerIdintThe player id of the user.

See also


Example
The following example turns the current user from spectator to player in the last joined Game Room:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER, onSpectatorToPlayerSwitch);
             sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER_ERROR, onSpectatorToPlayerSwitchError);
             
             // Switch spectator to player
             sfs.send(new SpectatorToPlayerRequest());
         }
         
         private function onSpectatorToPlayerSwitch(evt:SFSEvent):void
         {
             trace("Spectator " + evt.params.user + " is now a player");
         }
         
         private function onSpectatorToPlayerSwitchError(evt:SFSEvent):void
         {
             trace("Unable to become a player due to the following error: " + evt.params.errorMessage);
         }
         
SPECTATOR_TO_PLAYER_ERRORConstant 
public static const SPECTATOR_TO_PLAYER_ERROR:String = spectatorToPlayerError

The SFSEvent.SPECTATOR_TO_PLAYER_ERROR constant defines the value of the type property of the event object for a spectatorToPlayerError event.

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

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeintThe error code.

See also


Example
See the example provided in the SPECTATOR_TO_PLAYER constant description.
UDP_INITConstant 
public static const UDP_INIT:String = udpInit

The SFSEvent.UDP_INIT constant defines the value of the type property of the event object for a udpInit event.

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

PropertyTypeDescription
successBooleantrue if UDP connection initialization is successful, false otherwise.


Example
The following example initializes the UDP communication and sends a custom UDP request to an Extension:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.UDP_INIT, onUDPInit);
             
             sfs.initUDP(new AirUDPManager());
         }
         
         private function onUDPInit(evt:SFSEvent):void
         {
             if (evt.params.success)
             {
                 // Connection successful: execute an Extension call via UDP
                 sfs.send( new ExtensionRequest("udpTest", new SFSObject(), null, true) );
             }
             else
             {
                 trace("UDP initialization failed!");
             }
         }
         
USER_COUNT_CHANGEConstant 
public static const USER_COUNT_CHANGE:String = userCountChange

The SFSEvent.USER_COUNT_CHANGE constant defines the value of the type property of the event object for a userCountChange event.

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

PropertyTypeDescription
roomRoomAn object representing the Room in which the users count changed.
uCountintThe new users count (players in case of Game Room).
sCountintThe new spectators count (Game Room only).

See also


Example
The following example shows how to handle this event type:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.USER_COUNT_CHANGE, onUserCountChanged);
         }
         
         private function onUserCountChanged(evt:SFSEvent):void
         {
             var room:Room = evt.params.room;
             var uCount:int = evt.params.uCount;
             var sCount:int = evt.params.sCount;
             
             trace("Room: " + room.name + " now contains " + uCount + " users and " + sCount + " spectators");
         }
         
USER_ENTER_ROOMConstant 
public static const USER_ENTER_ROOM:String = userEnterRoom

The SFSEvent.USER_ENTER_ROOM constant defines the value of the type property of the event object for a userEnterRoom event.

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

PropertyTypeDescription
userUserAn object representing the user who joined the Room.
roomRoomAn object representing the Room that was joined by a user.

See also


Example
The following example shows how to handle this event type:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.USER_ENTER_ROOM, onUserEnterRoom);
         }
         
         private function onUserEnterRoom(evt:SFSEvent):void
         {
             var room:Room = evt.params.room;
             var user:User = evt.params.user;
             
             trace("User " + user.name + " just joined Room " + room.name);
         }
         
USER_EXIT_ROOMConstant 
public static const USER_EXIT_ROOM:String = userExitRoom

The SFSEvent.USER_EXIT_ROOM constant defines the value of the type property of the event object for a userExitRoom event.

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

PropertyTypeDescription
userUserAn object representing the user who left the Room.
roomRoomAn object representing the Room that was left by a user.

See also


Example
The following example shows how to handle this event type:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.USER_EXIT_ROOM, onUserExitRoom);
         }
         
         private function onUserExitRoom(evt:SFSEvent):void
         {
             var room:Room = evt.params.room;
             var user:User = evt.params.user;
             
             trace("User " + user.name + " just left Room " + room.name);
         }
         
USER_FIND_RESULTConstant 
public static const USER_FIND_RESULT:String = userFindResult

The SFSEvent.USER_FIND_RESULT constant defines the value of the type property of the event object for a userFindResult event.

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

PropertyTypeDescription
usersArrayA list of User objects representing the users matching the search criteria. If no user is found, the list is empty.


Example
The following example looks for all the users whose "age" User Variable is greater than 29:
         
         private function someMethod():void
         {
             sfs.addEventListener(SFSEvent.USER_FIND_RESULT, onUserFindResult);
             
             // Create a matching expression to find users with an "age" variable greater than 29:
             var exp:MatchExpression = new MatchExpression("age", NumberMatch.GREATER_THAN, 29);
             
             // Find the users
             sfs.send(new FindUserRequest(exp));
         }
         
         private function onUserFindResult(evt:SFSEvent):void
         {
             trace("Users found: " + evt.params.users);
         }
         
USER_VARIABLES_UPDATEConstant 
public static const USER_VARIABLES_UPDATE:String = userVariablesUpdate

The SFSEvent.USER_VARIABLES_UPDATE constant defines the value of the type property of the event object for a userVariablesUpdate event.

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

PropertyTypeDescription
userUserAn object representing the user who updated his own User Variables.
changedVarsArrayThe list of names of the User Variables that were changed (or created for the first time).


Example
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
                 ...
             }
         }
         
Examples
The following example shows a generic usage of a SFSEvent; please refer to the specific event types for the params object content:
     
     package sfsTest
     {
         import com.smartfoxserver.v2.SmartFox;
         import com.smartfoxserver.v2.core.SFSEvent;
         
         public class MyTest
         {
             private var sfs:SmartFox;
             
             public function MyTest()
             {
                 // Create a SmartFox instance
                 sfs = new SmartFox();
                 
                 // Add event handler for connection 
                 sfs.addEventListener(SFSEvent.CONNECTION, onConnection);
                 
                 // Connect to server
                 sfs.connect("127.0.0.1", 9933);    
             }
             
             // Handle connection event
             private function onConnection(evt:SFSEvent):void
             {
                 // Retrieve event parameters
                 var params:Object = evt.params;
                 
                 if (params.success)
                     trace("Connection established");
                 else
                     trace("Connection failed");
             }    
         }
     }