SmartFoxServer JoinRoom

stop();
import it.gotoandplay.smartfoxserver.*;
import it.gotoandplay.smartfoxserver.data.*;

sfs.addEventListener(SFSEvent.onConnection,onConnection);
sfs.addEventListener(SFSEvent.onJoinRoom, onJoinRoomHandler);

msg.text="";
msg2.text="";

gameUser.text = "AK";
var User_name:String = gameUser.text;
var joinedRoom:Room;

function onConnection(e:SFSEvent):void
{
sfs.login(sfs.defaultZone, User_name ,"");
//sfs.login(zeon,nickname,passwword);
msg2.text = "Status - " + (sfs.isConnected ? "connected" : "not connected");

//trace("My user ID is: " + sfs.myUserId);
//trace("My user Name is: " + sfs.myUserName);
}

function onJoinRoomHandler(e:SFSEvent):void
{
joinedRoom = e.params.room;
//Current room name and ID
msg.text= joinedRoom.getName()
+" room joined successfully" ;
//+"Room ID : " + joinedRoom.getId();

var users:Array = joinedRoom.getUserList()
for (var u:String in users)
User_list.text =(users[u].getName());


}


sfs.addEventListener(SFSEvent.onUserCountChange, onUserCountChangeHandler)

function onUserCountChangeHandler(evt:SFSEvent):void
{
// Assuming this is a game room

var roomName:String = evt.params.room.getName()
var playersNum:int = evt.params.room.getUserCount()
var spectatorsNum:int = evt.params.room.getSpectatorCount()

trace("Room " + roomName + "has " + playersNum + " players and " + spectatorsNum + " spectators")
}

0 comments:

Post a Comment