Packagecom.smartfoxserver.v2.requests
Classpublic class SpectatorToPlayerRequest
InheritanceSpectatorToPlayerRequest Inheritance com.smartfoxserver.v2.requests.BaseRequest

Turns the current user from spectator to player in a Game Room.

If the operation is successful, all the users in the target Room are notified with the spectatorToPlayer event. The operation could fail if no player slots are available in the Game Room at the time of the request; in this case the spectatorToPlayerError event is dispatched to the requester's client.

View the examples

See also

spectatorToPlayer event
spectatorToPlayerError event
PlayerToSpectatorRequest


Public Methods
 MethodDefined By
  
SpectatorToPlayerRequest(targetRoom:Room = null)
Creates a new SpectatorToPlayerRequest instance.
SpectatorToPlayerRequest
Constructor Detail
SpectatorToPlayerRequest()Constructor
public function SpectatorToPlayerRequest(targetRoom:Room = null)

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

Parameters
targetRoom:Room (default = null) — The Room object corresponding to the Room in which the spectator should be turned to player. If null, the last Room joined by the user is used.

See also

Examples
The following example turns the current user from spectator to player in the last joined Game Room:
     
     private function someMethod():void
     {
         sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER, onSpectatorToPlayerSwitch);
         sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER_ERROR, onSpectatorToPlayerSwitchError);
         
         // Switch spectator to player
         sfs.send(new SpectatorToPlayerRequest());
     }
     
     private function onSpectatorToPlayerSwitch(evt:SFSEvent):void
     {
         trace("Spectator " + evt.params.user + " is now a player");
     }
     
     private function onSpectatorToPlayerSwitchError(evt:SFSEvent):void
     {
         trace("Unable to become a player due to the following error: " + evt.params.errorMessage);
     }