Here's a working example, based on SFS PRO 1.5
1 - Zone definition
Code: Select all
<Zone name="simpleChat" uCountUpdate="true" buddyList="20" maxUsers="4000" customLogin="false" roomListVars="true">
<Rooms>
<Room name="The Hall" maxUsers="50" isPrivate="false" isTemp="false" autoJoin="true" uCountUpdate="true">
<Vars>
<Var name="name" type="s" private="false">Animal</Var>
<Var name="job" type="s" private="false">Muppets drummer</Var>
</Vars>
</Room>
</Rooms>
</Zone>
2- Code
Create a new Flash 8 document, and copy/paste the following code in the first frame. If necessary point your classpath to the API folder and then run the example.
Code: Select all
import it.gotoandplay.smartfoxserver.*
stop()
var ip:String = "127.0.0.1"
var port:Number = 9339
var zone:String = "simpleChat"
// Load the policy file from the server
System.security.loadPolicyFile("xmlsocket://" + ip + ":" + port)
var smartfox:SmartFoxClient = new SmartFoxClient()
smartfox.onConnection = handleConnection
smartfox.connect(ip, port)
//smartfox.debug = true
function handleConnection(success)
{
if (success)
{
trace(">> Connection successfull")
sendLogin()
}
else
{
trace("[ ERROR ]: Can't connect!")
}
}
function sendLogin()
{
smartfox.login(zone, "")
}
smartfox.onLogin = function(resObj:Object)
{
if (resObj.success)
{
// Login Successfull
trace(">> Login successfull. Nickname: " + resObj.name)
}
else
{
trace("[ ERROR ]: Login error. Server said: " + resObj.error)
}
}
smartfox.onRoomListUpdate = function(roomList:Object)
{
trace(">> Received the list of rooms\n")
trace("\tRoom List:")
trace("\t--------------------------------------------")
// Show the list of rooms
for (var i in roomList)
{
var r:Room = roomList[i]
trace("\t" + r.getName())
var o = r.getVariables()
for (var j:String in o)
trace("\t\t" + j + ": " + o[j])
}
// a blank line
trace("")
// Join the default room
this.autoJoin()
}
smartfox.onJoinRoom = function(roomObj:Room)
{
trace(">> Room: '" + roomObj.getName() + "' joined successfully")
}
smartfox.onJoinRoomError = function(errorMsg)
{
trace("[ ERROR ]: Error joining the room. Server said: " + errorMsg)
}
smartfox.onConnectionLost = function()
{
trace("[ ERROR ]: Connection with server was lost")
}
3- Example output
The above code is taken from the provided AS 2 template, found in our documentation. It will connect to the server, receive the list of rooms and dump the room variables and finally join a room.
Here's my output in the Flash output window:
>> Connection successfull
>> Login successfull. Nickname: guest_12
SET RVAR --> job
SET RVAR --> name
>> Received the list of rooms
Room List:
--------------------------------------------
The Hall
name: Animal
job: Muppets drummer
>> Room: 'The Hall' joined successfully
The test was done using a freshly installed SFS PRO 1.5
As you can see the variables for "The Hall" room are correctly shown in the trace.
Good luck