Package | com.smartfoxserver.v2.core |
Class | public class SFSEvent |
Inheritance | SFSEvent BaseEvent flash.events.Event |
The SFSEvent parent class provides a public property called params which contains specific parameters depending on the event type.
See also
Method | Defined 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 |
Constant | Defined 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 |
SFSEvent | () | Constructor |
public function SFSEvent(type:String, params:Object)
Creates a new SFSEvent instance.
Parameterstype:String — The type of event.
| |
params:Object — An object containing the parameters of the event.
|
clone | () | method |
override public function clone():Event
Duplicates the instance of the SFSEvent object.
ReturnsEvent — 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.
ReturnsString — A string containing all the properties of the SFSEvent object.
|
ADMIN_MESSAGE | Constant |
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:
Property | Type | Description |
---|---|---|
sender | User | An object representing the administrator user who sent the message. |
message | String | The message sent by the administrator. |
data | ISFSObject | An object containing custom parameters which might accompany the message. |
See also
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_FAILURE | Constant |
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
CONFIG_LOAD_SUCCESS | Constant |
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
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"); }
CONNECTION | Constant |
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:
Property | Type | Description |
---|---|---|
success | Boolean | The connection result: true if a connection was established, false otherwise. |
See also
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_HTTP | Constant |
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
CONNECTION_LOST | Constant |
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:
Property | Type | Description |
---|---|---|
reason | String | The reason of the disconnection, among those available in the ClientDisconnectionReason class. |
See also
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_RESUME | Constant |
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
CONNECTION_RETRY | Constant |
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
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_INIT | Constant |
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:
Property | Type | Description |
---|---|---|
success | Boolean | true if a unique encryption key was successfully retrieved via HTTPS, false if the transaction failed. |
errorMsg | String | If success is false , provides additional details on the occurred error. |
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_RESPONSE | Constant |
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:
Property | Type | Description |
---|---|---|
cmd | String | The 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. |
params | ISFSObject | An object containing custom data sent by the Extension. |
sourceRoom | Number | [DEPRECATED - Use room property] The id of the Room which the Extension is attached to (for Room Extensions only). |
room | Room | An object representing the Room which the Extension is attached to (for Room Extensions only). |
packetId | Number | The 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. |
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")); } }
INVITATION | Constant |
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:
Property | Type | Description |
---|---|---|
invitation | Invitation | An object representing the invitation received by the current user. |
See also
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_REPLY | Constant |
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:
Property | Type | Description |
---|---|---|
invitee | User | An object representing the user who replied to the invitation. |
reply | int | The answer to the invitation among those available as constants in the InvitationReply class. |
data | ISFSObject | An object containing custom parameters, for example a message describing the reason of refusal. |
See also
INVITATION_REPLY_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
LOGIN | Constant |
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:
Property | Type | Description |
---|---|---|
user | User | An object representing the user who performed the login. |
data | ISFSObject | An object containing custom parameters returned by a custom login system, if any. |
See also
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
LOGOUT | Constant |
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
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_UPDATE | Constant |
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:
Property | Type | Description |
---|---|---|
room | MMORoom | The MMORoom where the MMOItem whose Variables have been updated is located. |
mmoItem | MMOItem | The MMOItem whose variables have been updated. |
changedVars | Array | The list of names of the MMOItem Variables that were changed (or created for the first time). |
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_MESSAGE | Constant |
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:
Property | Type | Description |
---|---|---|
sender | User | An object representing the moderator user who sent the message. |
message | String | The message sent by the moderator. |
data | ISFSObject | An object containing custom parameters which might accompany the message. |
See also
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_MESSAGE | Constant |
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:
Property | Type | Description |
---|---|---|
sender | User | An object representing the user who sent the message. |
message | SFSObject | The content of the message: an object containing the custom parameters sent by the sender. |
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_PONG | Constant |
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:
Property | Type | Description |
---|---|---|
lagValue | int | The average of the last ten measured lag values, expressed in milliseconds. |
PLAYER_TO_SPECTATOR | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room in which the player is turned to spectator. |
user | User | An object representing the player who was turned to spectator. |
See also
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
PRIVATE_MESSAGE | Constant |
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:
Property | Type | Description |
---|---|---|
sender | User | An object representing the user who sent the message. |
message | String | The message sent by the user. |
data | ISFSObject | An object containing custom parameters which might accompany the message. |
See also
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_UPDATE | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | The Room in which the event occurred. |
addedUsers | Array | A list of User objects representing the users who entered the current user's Area of Interest. |
removedUsers | Array | A list of User objects representing the users who left the current user's Area of Interest. |
addedItems | Array | A list of MMOItem objects which entered the current user's Area of Interest. |
removedItems | Array | A list of MMOItem objects which left the current user's Area of Interest. |
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_MESSAGE | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room at which the message is targeted. |
sender | User | An object representing the user who sent the message. |
message | String | The message sent by the user. |
data | ISFSObject | An object containing custom parameters which might accompany the message. |
See also
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_ADD | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room that was created. |
See also
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_CHANGE | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room whose capacity was changed. |
See also
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
ROOM_CREATION_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
ROOM_FIND_RESULT | Constant |
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:
Property | Type | Description |
---|---|---|
rooms | Array | A list of Room objects representing the Rooms matching the search criteria. If no Room is found, the list is empty. |
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_SUBSCRIBE | Constant |
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:
Property | Type | Description |
---|---|---|
groupId | String | The name of the Group that was subscribed. |
newRooms | Array | A list of Room objects representing the Rooms belonging to the subscribed Group. |
See also
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
ROOM_GROUP_UNSUBSCRIBE | Constant |
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:
Property | Type | Description |
---|---|---|
groupId | String | The name of the Group that was unsubscribed. |
See also
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
ROOM_JOIN | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room that was joined. |
See also
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
ROOM_NAME_CHANGE | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room which was renamed. |
oldName | String | The previous name of the Room. |
See also
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
ROOM_PASSWORD_STATE_CHANGE | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room whose password was changed. |
See also
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
ROOM_REMOVE | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room that was removed. |
See also
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_UPDATE | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room where the Room Variable update occurred. |
changedVars | Array | The list of names of the Room Variables that were changed (or created for the first time). |
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | The description of the error. |
SPECTATOR_TO_PLAYER | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room in which the spectator is turned to player. |
user | User | An object representing the spectator who was turned to player. |
playerId | int | The player id of the user. |
See also
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_ERROR | Constant |
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | int | The error code. |
See also
UDP_INIT | Constant |
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:
Property | Type | Description |
---|---|---|
success | Boolean | true if UDP connection initialization is successful, false otherwise. |
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_CHANGE | Constant |
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room in which the users count changed. |
uCount | int | The new users count (players in case of Game Room). |
sCount | int | The new spectators count (Game Room only). |
See also
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_ROOM | Constant |
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:
Property | Type | Description |
---|---|---|
user | User | An object representing the user who joined the Room. |
room | Room | An object representing the Room that was joined by a user. |
See also
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_ROOM | Constant |
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:
Property | Type | Description |
---|---|---|
user | User | An object representing the user who left the Room. |
room | Room | An object representing the Room that was left by a user. |
See also
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_RESULT | Constant |
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:
Property | Type | Description |
---|---|---|
users | Array | A list of User objects representing the users matching the search criteria. If no user is found, the list is empty. |
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_UPDATE | Constant |
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:
Property | Type | Description |
---|---|---|
user | User | An object representing the user who updated his own User Variables. |
changedVars | Array | The list of names of the User Variables that were changed (or created for the first time). |
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 ... } }
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"); } } }