Packagecom.smartfoxserver.v2.requests
Classpublic class JoinRoomRequest
InheritanceJoinRoomRequest Inheritance com.smartfoxserver.v2.requests.BaseRequest

Joins the current user in a Room.

If the operation is successful, the current user receives a roomJoin event; otherwise the roomJoinError event is fired. This usually happens when the Room is full, or the password is wrong in case of password protected Rooms.

Depending on the Room configuration defined upon its creation (see the RoomSettings.events setting), when the current user joins it, the following events might be fired: userEnterRoom, dispatched to the other users inside the Room to warn them that a new user has arrived; userCountChange, dispatched to all clients which subscribed the Group to which the Room belongs, to update the count of users inside the Room.

View the examples

See also

roomJoin event
roomJoinError event
userEnterRoom event
userCountChange event
RoomSettings.events


Public Methods
 MethodDefined By
  
JoinRoomRequest(id:*, pass:String = null, roomIdToLeave:Number, asSpect:Boolean = false)
Creates a new JoinRoomRequest instance.
JoinRoomRequest
Constructor Detail
JoinRoomRequest()Constructor
public function JoinRoomRequest(id:*, pass:String = null, roomIdToLeave:Number, asSpect:Boolean = false)

Creates a new JoinRoomRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

Parameters
id:* — The id or the name of the Room to be joined.
 
pass:String (default = null) — The password of the Room, in case it is password protected.
 
roomIdToLeave:Number (default = NaN) — The id of a previously joined Room that the user should leave when joining the new Room. By default, the last joined Room is left; if a negative number is passed, no previous Room is left.
 
asSpect:Boolean (default = false)true to join the Room as a spectator (in Game Rooms only).

See also

Examples
The following example makes the user join an existing Room:
     
     private function someMethod():void
     {
         sfs.addEventListener(SFSEvent.ROOM_JOIN, onRoomJoined);
         sfs.addEventListener(SFSEvent.ROOM_JOIN_ERROR, onRoomJoinError);
         
         // Join a Room called "Lobby"
         sfs.send(new JoinRoomRequest("Lobby"));
     }
     
     private function onRoomJoined(evt:SFSEvent):void
     {
         trace("Room joined successfully: " + evt.params.room);
     }
     
     private function onRoomJoinError(evt:SFSEvent):void
     {
         trace("Room joining failed: " + evt.params.errorMessage);
     }