Posts Tagged ‘Advanced Chat Application’

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 ..

[java]

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)
}

[/java]

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 ..

[xml]

public function onRoomAdded(evt:SFSEvent):void {

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

public function onRoomDeleted(evt:SFSEvent):void {
updateRoomList(evt);
}

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

[/xml]

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 ? ๐Ÿ™‚

[xml]

private function btnNewRoom_click(evt:MouseEvent):void {
chatWindow_mc.createRoomWindow_mc.visible = true
chatWindow_mc.createRoomWindow_mc.ok_btn.addEventListener(MouseEvent.CLICK,handleCreateRoom)
}

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 = {}
roomObj.name = roomName
smartFoxObject.createRoom(roomObj)

}

}

[/xml]

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

[xml]

private function JoinSelectedRoom(evt:ListEvent):void {

if(chatWindow_mc.roomList.selectedItem != null){
var roomId:int = int(chatWindow_mc.roomList.selectedItem.data)
smartFoxObject.joinRoom(roomId)
}
}

[/xml]

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