SFSEvent

Event
SFSEvent

Description

Each event dispatched by the SmartFoxClient class is a SFSEvent object (it.gotoandplay.smartfoxserver.SFSEvent) which extends the flash.events.Event class.  The SFSEvent class provides a public property called params of type Object that can contain any number of parameters.

Example

package sfsTest
{
import it.gotoandplay.smartfoxserver.SmartFoxClient
import it.gotoandplay.smartfoxserver.SFSEvent

public class MyTest
{
private var smartFox:SmartFoxClient

public function MyTest()
{
// Create instance
smartFox = new SmartFoxClient()

// Add event handler for connection
smartFox.addEventListener(SFSEvent.onConnection, myOnConnectionHandler)

// Connect to server
smartFox.connect("127.0.0.1", 9339)
}

// Handle connection event
public function myOnConnectionHandler(evt:SFSEvent):void
{
if (evt.params.success)
{
trace("Great, successfully connected")
}
else
{
trace("Ouch, connection failed.")
}
}
}
}

Version

1.0.5

Status

Final

Author

The gotoAndPlay() Team

Copyright

© 2006-2007 gotoAndPlay()

http://www.gotoandplay.it

http://www.smartfoxserver.com

Summary
Each event dispatched by the SmartFoxClient class is a SFSEvent object (it.gotoandplay.smartfoxserver.SFSEvent) which extends the flash.events.Event class.
Dispatched when a message from the Administrator is received.
Dispatched when the buddy list is received.
Dispatched when an error occurs while loading the buddy list.
Dispatched when the status of a buddy in the buddy list changes.
Dispatched in response to a SmartFoxClient.getBuddyRoom request.
Dispatched when the connection with SmartFoxServer is lost.
Dispatched when an error occurs during the creation of a room.
Dispatched when the connection to SmartFoxServer succeeded or failed.
Dispatched when a debug message is traced by the SmartFoxServer API.
Dispatched when a response from a server-side extension is received.
Dispatched when a room is joined successfully.
Dispatched when an error occurs while joining a room.
Dispatched after the login to SmartFoxServer has been attempted.
Dispatched after the user logged out successfully.
Dispatched when a message from a Moderator is received.
Dispatched when an Actionscript object is received.
Dispatched when a public message is received.
Dispatched when a private message is received.
Dispatched when a response to the SmartFoxClient.getRandomKey request is received.
Dispatched when a new room is created.
Dispatched when a room is removed.
Dispatched when a room is left in multi-room mode, in response of a SmartFoxClient.leaveRoom request.
Dispatched when the list of rooms available in the Zone is received.
Dispatched when room variables are updated in a certain room.
Dispatched when a response to the SmartFoxClient.roundTripBench request is received.
Dispatched when a response to the SmartFoxClient.switchSpectator request is received.
Dispatched when the user/spectator count of a room changed.
Dispatched when a user joins the current room.
Dispatched when a user leaves the current room.
Dispatched when a user updates his/her User Variables.
Contains the parameters passed by the SmartFoxClient class.
The default contructor.
Create and returns a copy of the current instance.
Return a String containing all the properties of the current instance.

Constants

onAdminMessage

Dispatched when a message from the Administrator is received.

Admin messages are special messages that can be sent by an administrator to a user or group of users.  All client applications should handle this event, or users won’t be be able to receive important admin notifications!

The params object contains the following parameters.

  • message:String - the Administrator’s message.

onBuddyList

Dispatched when the buddy list is received.

The params object contains the following parameters.

  • list:Array - the buddy list.

Each element in the buddy list is an object containing the following parameters.

  • id:int - the buddy ID.
  • name:String - the buddy name.
  • isOnline:Boolean - the buddy status: true if the buddy is online; false if the buddy is offline.
  • variables:Object - an object with extra properties of the buddy.

onBuddyListError

Dispatched when an error occurs while loading the buddy list.

The params object contains the following parameters.

  • error:String - the error message.

onBuddyListUpdate

Dispatched when the status of a buddy in the buddy list changes.

The params object contains the following parameters.

  • buddy:Object - an object representing the buddy that has changed status.

The buddy object contains the following parameters.

  • id:int - the buddy ID.
  • name:String - the buddy name.
  • isOnline:Boolean - the buddy status: true if the buddy is online; false if the buddy is offline.
  • variables:Object - an object with extra properties of the buddy.

onBuddyRoom

Dispatched in response to a SmartFoxClient.getBuddyRoom request.

The params object contains the following parameters.

  • idList:Array - the list of id(s) of the rooms in which the buddy is currently logged.

onConnectionLost

Dispatched when the connection with SmartFoxServer is lost.

No parameters are available.

onCreateRoomError

Dispatched when an error occurs during the creation of a room.

Usually this happens when a client tries to create a room but its name is already taken.

The params object contains the following parameters.

  • error:String - the error message.

onConnection

Dispatched when the connection to SmartFoxServer succeeded or failed.

The params object contains the following parameters.

  • success:Boolean - the connection result: true if the connection succeeded; false if the connection failed.
  • error:String - an error message if connection failed.

onDebugMessage

Dispatched when a debug message is traced by the SmartFoxServer API.

In order to receive this event you have to previously set the SmartFoxClient.debug flag to true.

The params object contains the following parameters.

  • message:String - the debug message.

onExtensionResponse

Dispatched when a response from a server-side extension is received.

The params object contains the following parameters.

  • dataObj:Object - the response object; by convention a string property called _cmd is always present.  The property contains the name of the server action that is responding.
  • type:String - one of the following response protocol types: SmartFoxClient.XTMSG_TYPE_XML, SmartFoxClient.XTMSG_TYPE_STR, SmartFoxClient.XTMSG_TYPE_JSON.

onJoinRoom

Dispatched when a room is joined successfully.

The params object contains the following parameters.

  • room:Room - the Room object representing the joined room.

onJoinRoomError

Dispatched when an error occurs while joining a room.

This can happen, for example, when the room you want to join is full.

The params object contains the following parameters.

  • error:String - the error message.

onLogin

Dispatched after the login to SmartFoxServer has been attempted.

The params object contains the following parameters.

  • resObj:Object - the response object sent by the server.

The response object contains the following parameters.

  • success:Boolean - the login result: true if the login was successful; false if login failed.  The reason for failure is explained in the error parameter.
  • name:String - your current username.  The server sends the username back to the client because not all usernames are valid (for example those containing bad words may have been filtered).
  • error:String - the error description sent by the server (in case of login failed).

onLogout

Dispatched after the user logged out successfully.

The user will still be connected to the server but he will have to login again in a Zone, in order to interact with the server.

No parameters are available.

onModeratorMessage

Dispatched when a message from a Moderator is received.

The params object contains the following parameters.

  • message:String - the Administrator’s message.
  • sender:User - the User object representing the user that sent the message.

onObjectReceived

Dispatched when an Actionscript object is received.

The params object contains the following parameters.

  • obj:Object - the Actionscript object received.
  • sender:User - the User object representing the user that sent the Actionscript object.

onPublicMessage

Dispatched when a public message is received.

The params object contains the following parameters.

  • message:String - the public message received.
  • sender:User - the User object representing the user that sent the public message.
  • roomId:int - the id of the room where the sender is.

onPrivateMessage

Dispatched when a private message is received.

The params object contains the following parameters.

  • message:String - the private message received.
  • sender:User - the User object representing the user that sent the private message; this property is undefined if the sender isn’t in the same room of the recipient.
  • roomId:int - the id of the room where the sender is.
  • userId:int - the user id of the sender (useful when sending private messages across different rooms).

onRandomKey

Dispatched when a response to the SmartFoxClient.getRandomKey request is received.

The params object contains the following parameters.

  • key:String - the unique random key generated by the server.

onRoomAdded

Dispatched when a new room is created.

The params object contains the following parameters.

  • room:Room - the Room object representing the room that was created.

onRoomDeleted

Dispatched when a room is removed.

The params object contains the following parameters.

  • room:Room - the Room object representing the room that was removed.

onRoomLeft

Dispatched when a room is left in multi-room mode, in response of a SmartFoxClient.leaveRoom request.

The params object contains the following parameters.

  • roomId:int - the id of the room that was left.

onRoomListUpdate

Dispatched when the list of rooms available in the Zone is received.

The params object contains the following parameters.

  • roomList:Array - the list of Room objects available in the Zone.

onRoomVariablesUpdate

Dispatched when room variables are updated in a certain room.

A client receives these notifications only from the room(s) where he is currently logged in.  Also, only the variables that changed are transmitted.

The params object contains the following parameters.

  • room:Room - the Room object representing the room where the update took place.
  • changedVars:Array - an associative array with the names of the changed variables as keys.  You can also iterate through numeric indexes (0 to length) to get the names of the variables that changed.

onRoundTripResponse

Dispatched when a response to the SmartFoxClient.roundTripBench request is received.

The params object contains the following parameters.

  • elapsed:int - the amount of milliseconds that it takes to a message to go from the client to the server and back to the client.

onSpectatorSwitched

Dispatched when a response to the SmartFoxClient.switchSpectator request is received.

The params object contains the following parameters.

  • success:Boolean - the switch result: true if the spectator was turned into a player, otherwise false.
  • newId:int - the new player id of the user (all spectators have their playerId property set to -1).
  • room:Room - the Room object representing the room where the switch occurred.

onUserCountChange

Dispatched when the user/spectator count of a room changed.

The params object contains the following parameters.

  • room:Room - the Room object representing the room where the change occurred.

onUserEnterRoom

Dispatched when a user joins the current room.

The params object contains the following parameters.

  • roomId:int - the id of the room joined by a user.
  • user:User - the User object representing the user that joined the room.

onUserLeaveRoom

Dispatched when a user leaves the current room.

The params object contains the following parameters.

  • roomId:int - the id of the room left by the user.
  • userId:int - the id of the user that left the room (or got disconnected).
  • userName:String - the name of the user.

onUserVariablesUpdate

Dispatched when a user updates his/her User Variables.

The params object contains the following parameters.

  • user:User - the User object representing the user updating the variables.
  • changedVars:Array - n associative array with the names of the changed variables as keys.  You can also iterate through numeric indexes (0 to length) to get the names of the variables that changed.

Variables

params

public var params: Object

Contains the parameters passed by the SmartFoxClient class.

Functions

SFSEvent

public function SFSEvent(type: String,
params: Object)

The default contructor.

Parameters

typethe type of event (see the constants in this class).
paramsthe parameters object for the event.

Example

See the SFSEvent class description.

See also

params

clone

function clone():Event

Create and returns a copy of the current instance.

Parameters

None.

Return

Eventa copy of the current instance.

toString

function toString():String

Return a String containing all the properties of the current instance.

Parameters

None.

Return

Stringa string representation of the current instance.
public function getBuddyRoom(buddy: Object):void
Request the roomId(s) of the room(s) a buddy is currently joined to.
public function getRandomKey():void
Gets a random string key from the server.
public function leaveRoom(roomId: int):void
Disconnect the user from the specified room.
public function roundTripBench():void
Send a roundTrip request to the server to test the speed of the connection.
public function switchSpectator(roomId: int = -1):void
Turn a spectator inside a game room into a player.
public var params: Object
Contains the parameters passed by the SmartFoxClient class.
public function SFSEvent(type: String,
params: Object)
The default contructor.
function clone():Event
Create and returns a copy of the current instance.
function toString():String
Return a String containing all the properties of the current instance.
public var debug: Boolean
Toggles the client-side debugging informations.
The Room class is used internally by the SmartFoxClient object to store the properties of each room.
The User class is used internally by the SmartFoxClient object to store the properties of each user.