Archive for the ‘Simple Chat Application : Flash CS4’ Category

Simple Chat Application:Part- 5

October 30th, 2010 by aabhaanjan

In handleSmartFoxEvents() function we have called  following functions

//Here we are going to handle all the smartfoxEvents  for now here I am showing  6 function later

We will need to add more.


private function handleSmartFoxEvents():void{

smartFoxObject.addEventListener (SFSEvent.onExtensionResponse, onExtensionResponse);

smartFoxObject.addEventListener(SFSEvent.onRoomListUpdate, onRoomListUpdate)

smartFoxObject.addEventListener(SFSEvent.onUserCountChange, onUserCountChange)

smartFoxObject.addEventListener(SFSEvent.onJoinRoom, onJoinRoom)

smartFoxObject.addEventListener(SFSEvent.onJoinRoomError, onJoinRoomError)

smartFoxObject.addEventListener(SFSEvent.onPublicMessage, onPublicMessage)

smartFoxObject.addEventListener(SFSEvent.onPrivateMessage, onPrivateMessage)

smartFoxObject.addEventListener(SFSEvent.onUserEnterRoom, onUserEnterRoom)

smartFoxObject.addEventListener(SFSEvent.onUserLeaveRoom, onUserLeaveRoom)

smartFoxObject.addEventListener(SFSEvent.onLogout, onLogout)



Now lets discuss it in detail :

onExtensionResponse() : this  will give us all server responses defined in the server side. Dispatched when a command/response from a server-side extension is received.

onRoomListUpdate(): this event  is dispatched when the list of rooms of  the current zone is received.
If the default login mechanism provided by SmartFoxServer is used, then this event is dispatched right after a successful login.

onUserCountChange(): this event is dispatched when the number of users and/or spectators changes in a room of the current zone. This event allows to keep track in real-time of the status of all the zone rooms in terms of users and spectators. If any user joins or leave the room it gets updated automatically.

onJoinRoom (): this event is dispatched when a user joins any room  successfully

onJoinRoomError(): while joining a room any error occurs, this event is dispatched. This error could happen, for example, if the user is trying to join a room which is currently full  it will throw an error.In our application we would like to trace the error  so we will get using evt.params.error

onPublicMessage(): this event is dispatched when a user  want to send a public message for all the users.

onPrivateMessage ():this event is dispatched when a user  want to send a public message for all the users.

onUserEnterRoom(): this event is dispatched when another user joins the current room.

onUserLeaveRoom(): this event is dispatched  when a user leaves the current room. This  event is also dispatched when a user gets disconnected from the server.

onLogout (): Dispatched when the user logs out successfully. After a successful logout the user is still connected to the server, but he/she has to login again into a zone, in order to be able to interact with the server. When a user will want to logout from the screen he will need to click on the logout button. On clicking log out button this function will be called.

Tags: , , , , , , , , , , , , , , , ,

Simple Chat Application:Part 2

October 18th, 2010 by aabhaanjan

As discussed in our last chapter lets move to the code part more deeply 🙂

So now we need to load the config and establish the connection first  our code will look like this


Lets start with init() function where I am initializing the smartfoxserver’s object and loading the config.

loadConfigData():- Here I am loading the configData which is basically an XML file out side in the folder

containg ip, zone and port.

onConfigLoaded(): This function is called after successful loading of config XML. Inside this function I am calling two more functions named connectionEventsOfSFS() and handleConnectionToSFS().

connectionEventsOfSFS():- here basically I am enabling the SmartFoxServer’s event for onConnection established and on connection lost.

Tags: , , , , , , , , ,