Packagecom.smartfoxserver.v2.requests
Classpublic class PlayerToSpectatorRequest
InheritancePlayerToSpectatorRequest Inheritance com.smartfoxserver.v2.requests.BaseRequest

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

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

View the examples

See also

playerToSpectator event
playerToSpectatorError event
SpectatorToPlayerRequest


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

Creates a new PlayerToSpectatorRequest 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 player should be turned to spectator. If null, the last Room joined by the user is used.

See also

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