Posts Tagged ‘onJoinRoomError’

Advanced Chat Application-Part 2

November 9th, 2010 by aabhaanjan

lets move to the few additional functions where we are going to create new room , join Selected room etc ..


private function handleSmartFoxEvents():void {

smartFoxObject.addEventListener(SFSEvent.onExtensionResponse, onExtensionResponse);
smartFoxObject.addEventListener(SFSEvent.onRoomListUpdate, onRoomListUpdate);
smartFoxObject.addEventListener(SFSEvent.onJoinRoom, onJoinRoom);
smartFoxObject.addEventListener(SFSEvent.onJoinRoomError, onJoinRoomError);
smartFoxObject.addEventListener(SFSEvent.onUserCountChange, onUserCountChange);
smartFoxObject.addEventListener(SFSEvent.onUserEnterRoom, onUserEnterRoom);
smartFoxObject.addEventListener(SFSEvent.onUserLeaveRoom, onUserLeaveRoom);
smartFoxObject.addEventListener(SFSEvent.onPublicMessage, onPublicMessage);
smartFoxObject.addEventListener(SFSEvent.onPrivateMessage, onPrivateMessage);

smartFoxObject.addEventListener(SFSEvent.onRoomAdded, onRoomAdded)
smartFoxObject.addEventListener(SFSEvent.onRoomDeleted, onRoomDeleted)
smartFoxObject.addEventListener(SFSEvent.onCreateRoomError, onCreateRoomError)

smartFoxObject.addEventListener(SFSEvent.onLogout, onLogout)


as above mentioned we have added three additional sfs events where on room creation , deletion and on any room creation error dispatched the functions .. now lets discuss the code bit more ..


public function onRoomAdded(evt:SFSEvent):void {

var room:Room =
chatWindow_mc.roomList.addItem( {label:room.getName(),data: room.getId() });

public function onRoomDeleted(evt:SFSEvent):void {

public function onCreateRoomError(evt:SFSEvent):void {
trace(“error “+evt.params.error);


onRoomAdded : we need to update the room list and add the current room.

onRoomDeleted:we need to update the room list and delete the current room.

onCreateRoomError: here we will be able to see the error if on creation of room we will get any error.

Now how we are going to create the new room ? 🙂


private function btnNewRoom_click(evt:MouseEvent):void {
chatWindow_mc.createRoomWindow_mc.visible = true

private function handleCreateRoom(evt:MouseEvent):void {
chatWindow_mc.createRoomWindow_mc.visible = false
var roomName:String = chatWindow_mc.createRoomWindow_mc.room_name.text

if (roomName.length > 0)

var roomObj:Object = {} = roomName




for that we are going to use above mentioned function. Now to join a specific room :


private function JoinSelectedRoom(evt:ListEvent):void {

if(chatWindow_mc.roomList.selectedItem != null){
var roomId:int = int(


So now our advanced chat is almost completed .. why almost ? 🙂 becuase there are many more actions  which can be included in advanced chat

for example adding password protected room, defining the max number of user , making buddy etc… 🙂

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

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: , , , , , , , , , , , , , , , ,