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