new EventDispatcher()

Developers never istantiate the EventDispatcher class: this is done internally by the SmartFoxServer 2X API.

Methods

addEventListener(evtType, callback, scope)

Registers an event listener function that will receive notification of an event.

If you no longer need an event listener, remove it by calling the removeEventListener() method, or memory issues could arise. In fact event listeners are not automatically removed from memory.

Example

This example shows how to add a number of common event listeners to the SmartFox instance, usually during initialization:

function init()
{
	sfs = new SFS2X.SmartFox();

	// Add LoggerEvent listeners
	sfs.logger.addEventListener(SFS2X.LoggerEvent.DEBUG, onDebugMessage, this);
	sfs.logger.addEventListener(SFS2X.LoggerEvent.INFO, onInfoMessage, this);
	sfs.logger.addEventListener(SFS2X.LoggerEvent.WARNING, onWarningMessage, this);
	sfs.logger.addEventListener(SFS2X.LoggerEvent.ERROR, onErrorMessage, this);

	// Add SFSEvent listeners
	sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
	sfs.addEventListener(SFS2X.SFSEvent.CONNECTION_LOST, onConnectionLost, this);
	sfs.addEventListener(SFS2X.SFSEvent.LOGIN_ERROR, onLoginError, this);
	sfs.addEventListener(SFS2X.SFSEvent.LOGIN, onLogin, this);
	sfs.addEventListener(SFS2X.SFSEvent.LOGOUT, onLogout, this);
	sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError, this);
	sfs.addEventListener(SFS2X.SFSEvent.ROOM_JOIN, onRoomJoin, this);
}

Parameters

Name Type Optional Description

evtType

string

 

The type of event to listen to, among those available in the SFSEvent, SFSBuddyEvent and LoggerEvent classes.

callback

function()

 

The listener function that processes the event. This function should accept an object as its only parameter, which in turn contains the event parameters.

scope

number

 

The object that acts as a context for the event listener: it is the object that acts as a "parent scope" for the callback function, thus providing context (i.e. access to variables and other mehtods) to the function itself.

See also
SFSEvent
SFSBuddyEvent
LoggerEvent
EventDispatcher#removeEventListener

removeEventListener(evtType, callback)

Removes an event listener.

Parameters

Name Type Optional Description

evtType

string

 

The type of event to remove, among those available in the SFSevent, SFSBuddyEvent and LoggerEvent classes.

callback

function()

 

The listener function to be removed.

See also
SFSEvent
SFSBuddyEvent
EventDispatcher#addEventListener