Pages

Saturday, May 12, 2012

Join Room in SmartFoxServer 2X



sfs.send( new JoinRoomRequest("The Lobby") );


The server will in turn respond with one of the following events:
  • SFSEvent.ROOM_JOIN, if the operation is successful
  • SFSEvent.ROOM_JOIN_ERROR, if an error occurred
As usual we will need to register the events in our main SmartFox class instance to be
notified of the result of the join operation. This is the full ActionScript 3 code
required to handle both cases (very similar for other languages).
This code is usually executed during the application initialization:

var sfs:SmartFox = new SmartFox();
sfs.addEventListener(SFSEvent.ROOM_JOIN, onJoin);
sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, onJoinError);


This code is executed after a successful login:


sfs.send( new JoinRoomRequest("The Lobby") );


And these are the event listeners:



public function onJoin(evt:SFSEvent):void
{
    trace("Joined Room: " + evt.params.room.name);
}
public function onJoinError(evt:SFSEvent):void
{
    trace("Join failed: " + evt.params.errorMessage);
}

1 comments:

Unknown said...

I bookmark this site!

Post a Comment