Code: Select all
createRoom(Room, -1)Code: Select all
17:16:39.659 - [ INFO ] > Room [ new_room_name ] created!Code: Select all
trace("sfs_room_create.as loaded...");
import it.gotoandplay.smartfoxserver.*
////////////////////////////////// VAR ///////////////////////////////////
var newRoomName; // new room to create
var serverIp = "127.0.0.1"; // localhost
var port:Number = 9339;
var zone:String = "testzone";
var username = "slartibartfast";
///////////////////////////////// SCRIPT /////////////////////////////////
stop();
_global.smartfox = new SmartFoxClient();
smartfox.debug = true;
// register for sfs events...
smartfox.onRoomAdded = createRoomCallBack;
smartfox.onCreateRoomError = createRoomErrorCallBack;
smartfox.onRoomListUpdate = getRoomListCallBack;
smartfox.onLogin = logInCallBack;
// connect to sfs
smartfox.onConnection = gameServerConnectCallBack;
smartfox.connect(serverIp, port);
////////////////////////////////// FUNC //////////////////////////////////
function gameServerConnectCallBack()
{
trace("gameServerConnectCallBack()");
smartfox.login(zone, username);
listGameRooms();
}
function logInCallBack()
{
trace("logInCallBack()");
listGameRooms();
}
function getGameRooms()
{
trace("getGameRooms()");
smartfox.getRoomList();
}
function listGameRooms()
{
trace("listGameRooms()");
gameListing_lt.removeAll();
for (var i:String in smartfox.roomList)
{
var r:Room = smartfox.roomList[i];
trace("list room " + i + " : " + r.getName());
gameListing_lt.addItem( r.getName(), i );
}
}
function createNewRoom()
{
trace("createNewRoom()");
for (var i:String in smartfox.roomList)
{
var r:Room = smartfox.roomList[i];
trace("scan room names for dupe " + i + " (" + r.getName() + ")");
if (newRoomName == r.getName())
{
trace("The room name " + newRoomName + " already exists. Please re-enter a different room name.");
return;
}
}
var room:Object = new Object();
room.name = newRoomName;
room.password = "";
room.maxUsers = 6;
room.isGame = true;
trace("I don't seem to be getting the onRoomAdded server event." );
trace("Lets trace some data to insure that the event is registered for, and active" );
trace("smartfox.onRoomAdded = " + smartfox.onRoomAdded);
trace("typeof(smartfox.onRoomAdded) = " + typeof(smartfox.onRoomAdded) );
trace("lets call the function now without a responce object to see how it behaves" );
trace("..." );
smartfox.onRoomAdded(null);
trace("..." );
trace("ok, now lets call smartfox.createRoom() and see what happends..." );
smartfox.createRoom(room, -1);
}
// callback function after room creation
//
function createRoomCallBack(roomObj:Room)
{
trace("createRoomCallBack( " + roomObj.getName() + " )");
trace("Lets check the paramater sent, if it's null we will exit, if not.. do other stuff");
if (roomObj == null)
{
trace("hey, you sent me a null paramater. I'm exiting.");
return;
}
else
{
trace("param is not null. lets call smartFox.getRoomList() and see if the new room is listed");
smartfox.getRoomList()
}
trace("roomObj.getName() = " + roomObj.getName());
}
function createRoomErrorCallBack(errorMsg:String)
{
trace("createRoomErrorCallBack() ... " + errorMsg);
}
function getRoomListCallBack()
{
trace("getRoomListCallBack()");
listGameRooms()
}
// EOF
p.s. onCreateRoomError doesn't appear to be working either.