Packagecom.whirled.game
Classpublic class GameSubControl
InheritanceGameSubControl Inheritance AbstractSubControl Inheritance AbstractControl Inheritance flash.events.EventDispatcher

Access game-specific controls. Do not instantiate this class yourself. Access it via GameControl.game.



Public Properties
 PropertyDefined by
  seating : SeatingSubControl
[read-only] Access the 'seating' subcontrol.
GameSubControl
Public Methods
 MethodDefined by
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener.
AbstractControl
  
amInControl():Boolean
Returns true if we are in control of this game.
GameSubControl
  
amServerAgent():Boolean
Returns true if this control is connected to a server agent.
GameSubControl
 Inherited
doBatch(fn:Function, ... args):void
Execute the specified function as a batch of commands that will be sent to the server together.
AbstractSubControl
  
endGameWithScore(score:int, gameMode:int = 0):void
A convenience function for ending a single player game with the supplied score.
GameSubControl
  
endGameWithScores(playerIds:Array, scores:Array, payoutType:int, gameMode:int = 0):void
Ends the game, reporting the scores earned by each player in the game, awarding coins according to the specified strategy and updating player ratings.
GameSubControl
  
endGameWithWinners(winnerIds:Array, loserIds:Array, payoutType:int):void
Ends the game, declaring which players are the winners (if players tie, more than one player can be declared a winner.
GameSubControl
  
endRound(nextRoundDelay:int = 0):void
Ends the current round.
GameSubControl
  
getConfig():Object
Get any game-specific configurations that were set up in the lobby.
GameSubControl
  
Returns the player id of the client that is in control of this game.
GameSubControl
  
getItemPacks():Array
Returns the set of all item packs available to this game as an array of objects with the following properties:
     ident - string identifier of item pack
     name - human readable name of item pack
     mediaURL - URL for item pack content
     
GameSubControl
  
getLevelPacks():Array
Returns the set of all level packs available to this game as an array of objects with the following properties:
     ident - string identifier of item pack
     name - human readable name of item pack
     mediaURL - URL for item pack content
     premium - boolean indicating that content is premium or not
     
GameSubControl
  
getMyId():int
Returns this client's player id.
GameSubControl
  
Returns the player ids of all occupants in the game room: players and watchers.
GameSubControl
  
getOccupantName(playerId:int):String
Get the display name of the specified occupant.
GameSubControl
  
getParty(partyId:int):PartySubControl
Get the party control for the specified party.
GameSubControl
  
getPartyIds():Array
Return the ids of all parties presently in this game.
GameSubControl
  
getRound():int
Returns the current round number.
GameSubControl
  
Returns the player id of the current turn holder, or 0 if it's nobody's turn.
GameSubControl
 Inherited
isConnected():Boolean
Are we connected and running inside the whirled environment, or has someone just loaded up our SWF by itself?
AbstractSubControl
  
isInPlay():Boolean
Is the game currently in play?
GameSubControl
  
isMyTurn():Boolean
A convenience method to just check if it's our turn.
GameSubControl
  
loadItemPackData(ident:String, onLoaded:Function, onFailure:Function):void
Loads the binary data for the item pack with the specified ident.
GameSubControl
  
loadLevelPackData(ident:String, onLoaded:Function, onFailure:Function):void
Loads the binary data for the level pack with the specified ident.
GameSubControl
  
playerReady():void
If the game was not configured to auto-start, which is determined by the 2nd parameter to the GameControl constructor, then all player clients must call this function to let the server know that they are ready, at which point the game will be started.
GameSubControl
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Unregisters an event listener.
AbstractControl
  
restartGameIn(seconds:int):void
Requests to start the game again in the specified number of seconds.
GameSubControl
  
startNextTurn(nextPlayerId:int = 0):void
Start the next player's turn.
GameSubControl
  
systemMessage(msg:String):void
Send a system chat message that will be seen by everyone in the game room, even observers.
GameSubControl
  
takeOverPlayer(playerId:int):void
Tells the system that the server agent will take over for the specified player.
GameSubControl
Events
 EventSummaryDefined by
   Dispatched when the controller changes for the game.GameSubControl
   Dispatched when the game ends.GameSubControl
   Dispatched when the game starts, usually after all players are present.GameSubControl
   Dispatched when an occupant enters the game.GameSubControl
   Dispatched when an occupant leaves the game.GameSubControl
   Dispatched when a party arrives in the game.GameSubControl
   Dispatched when a party leaves the game.GameSubControl
   Dispatched when a round ends.GameSubControl
   Dispatched when a round starts.GameSubControl
   Dispatched when the turn changes in a turn-based game.GameSubControl
 Inherited Event.UNLOAD Dispatched when the SWF using this control has been unloaded.AbstractControl
   Dispatched when a user chats.GameSubControl
Public Constants
 ConstantDefined by
  CASCADING_PAYOUT : int = 0
[static] Cascading payout skews awards toward the winners by giving 50% of last place's payout to first place, 25% to the next inner pair of opponents (third to second in a four player game, for example), and so on.
GameSubControl
  PROPORTIONAL : int = 3
[static] Proportional is used for games where there is no way to measure player's performance against a global standard, but where the scores are subjective to the particular players currently playing.
GameSubControl
  SERVER_AGENT_ID : int = -2.147483648E9
[static] ID constant returned by getMyId when called by a game's server agent.
GameSubControl
  TO_EACH_THEIR_OWN : int = 2
[static] Each player receives a payout based only on their score and not influenced by the scores of any other player.
GameSubControl
  WINNERS_TAKE_ALL : int = 1
[static] Winner takes all splits the total coins available to award to all players in the game among those identified as winners at the end of the game.
GameSubControl
Property detail
seatingproperty
seating:SeatingSubControl  [read-only]

Access the 'seating' subcontrol. Note that this will be null in "party" games, because there's no such thing as seats.

Implementation
    public function get seating():SeatingSubControl
Method detail
amInControl()method
public function amInControl():Boolean

Returns true if we are in control of this game. False if another client is in control. Always returns false when called from the game's server agent.

Returns
Boolean
amServerAgent()method 
public function amServerAgent():Boolean

Returns true if this control is connected to a server agent.

Returns
Boolean
endGameWithScore()method 
public function endGameWithScore(score:int, gameMode:int = 0):void

A convenience function for ending a single player game with the supplied score. This is equivalent to: endGameWithScores([ getMyId() ], [ score ], TO_EACH_THEIR_OWN). Please read the endGameWithScores documentation for information on the range of allowable scores.

Note that if a single player game is ended with a score of zero, it will be assumed that the player in question abandoned the game and no coins will be paid out, nor will their rating be updated.

Parameters
score:int
 
gameMode:int (default = 0)
endGameWithScores()method 
public function endGameWithScores(playerIds:Array, scores:Array, payoutType:int, gameMode:int = 0):void

Ends the game, reporting the scores earned by each player in the game, awarding coins according to the specified strategy and updating player ratings.

Coins are awarded based on the supplied payout type, either CASCADING_PAYOUT, WINNERS_TAKE_ALL or TO_EACH_THEIR_OWN. In the case of WINNERS_TAKE_CALL, the highest scoring player or players will be considered the winner(s) and in the case of CASCADING_PAYOUT, players will be ranked according to their scores, higher scores being considered better.

If coins are awarded, a COINS_AWARDED event will be dispatched before the GAME_ENDED event is dispatched informing the client that the game has ended.

Both rating and a player's coin payout will be adjusted based on their score. Whirled will track every score reported by your game for its entire existence and will convert newly reported scores to a percentile value between 0 and 99 (inclusive) indicating the percentage of scores in the entire score history that are below the reported score. That percentile ranking will be used to adjust the players rating as well as to determine their individual coin payout.

Note that scores must be positive integers between 0 and 2^30 (1073741824) and higher scores are considered better, so if your game naturally operates with scores where lower is better (elapsed time in a racing game, for example), then you must convert your score to a positive integer by, for example, subtracting your score from a hypothentical worse possible score. For example:

score = Math.max(WORST_POSSIBLE_TIME - actualTime, 1)

Note that if a game is ended with all players scores equal of zero, it will be assumed that the players in question abandoned the game and no coins will be paid out, nor will their ratings be updated.

The gameMode parameter allows you to maintain separate score distributions for different game modes. If your game contains different modes which use scores that are not comparable to one another, or you have various game levels for which you would like to track individual score distributions, you can assign each an integer value between 0 and 99. Only 100 game modes are allowed.

Parameters
playerIds:Array
 
scores:Array
 
payoutType:int
 
gameMode:int (default = 0)
endGameWithWinners()method 
public function endGameWithWinners(winnerIds:Array, loserIds:Array, payoutType:int):void

Ends the game, declaring which players are the winners (if players tie, more than one player can be declared a winner. In addition to ending the game, this method awards coins and updates players ratings.

Coins are awarded based on the supplied payout type, either CASCADING_PAYOUT or WINNERS_TAKE_ALL. In the case of WINNERS_TAKE_ALL, the losers will have all of their individual coin payouts combined into a pool and that pool will be evenly divided among the winners and added to their respective individual coin payouts. In the case of CASCADING_PAYOUT, the losers will only have 50% of their individual coin payouts given to the winners.

If coins are awarded, a COINS_AWARDED event will be dispatched before the GAME_ENDED event is dispatched informing the client that the game has ended.

Players' ratings will also be updated using the Elo algorigthm wherein each player is rated against the average ratings of the players that the defeated or were defeated by. In a two player game this degenerates into the standard Elo algorithm.

Parameters
winnerIds:Array
 
loserIds:Array
 
payoutType:int

See also

endRound()method 
public function endRound(nextRoundDelay:int = 0):void

Ends the current round. If nextRoundDelay is greater than zero, the next round will be started in the specified number of seconds, otherwise no next round will be started. This method should not be called at the end of the last round, instead endGame() should be called.

Parameters
nextRoundDelay:int (default = 0)
getConfig()method 
public function getConfig():Object

Get any game-specific configurations that were set up in the lobby.

Returns
Object — an Object containing config names mapping to their values.
getControllerId()method 
public function getControllerId():int

Returns the player id of the client that is in control of this game.

Returns
int
getItemPacks()method 
public function getItemPacks():Array

Returns the set of all item packs available to this game as an array of objects with the following properties:

     ident - string identifier of item pack
     name - human readable name of item pack
     mediaURL - URL for item pack content
     

Returns
Array
getLevelPacks()method 
public function getLevelPacks():Array

Returns the set of all level packs available to this game as an array of objects with the following properties:

     ident - string identifier of item pack
     name - human readable name of item pack
     mediaURL - URL for item pack content
     premium - boolean indicating that content is premium or not
     

Returns
Array
getMyId()method 
public function getMyId():int

Returns this client's player id. If this method is called from the game's server agent, the result is SERVER_AGENT_ID. The method amServerAgent can be used to explicitly test for this case.

Returns
int

See also

getOccupantIds()method 
public function getOccupantIds():Array

Returns the player ids of all occupants in the game room: players and watchers. The occupants will be returned in no particular order, and unlike getPlayerIds() there will never be any zeros in the array.

Returns
Array
getOccupantName()method 
public function getOccupantName(playerId:int):String

Get the display name of the specified occupant. Two players may have the same name: always use playerId to purposes of identification and comparison. The name is for display only. Will be null is the specified playerId is not present.

Parameters
playerId:int

Returns
String
getParty()method 
public function getParty(partyId:int):PartySubControl

Get the party control for the specified party. Note that this will always return a PartySubControl, even for partyIds that are not present in the game. Be careful.

Parameters
partyId:int

Returns
PartySubControl
getPartyIds()method 
public function getPartyIds():Array

Return the ids of all parties presently in this game.

Returns
Array
getRound()method 
public function getRound():int

Returns the current round number. Rounds start at 1 and increase if the game calls endRound with a next round timeout. Between rounds, it returns a negative number, corresponding to the negation of the round that just ended.

Returns
int

See also

getTurnHolderId()method 
public function getTurnHolderId():int

Returns the player id of the current turn holder, or 0 if it's nobody's turn.

Returns
int
isInPlay()method 
public function isInPlay():Boolean

Is the game currently in play?

Returns
Boolean
isMyTurn()method 
public function isMyTurn():Boolean

A convenience method to just check if it's our turn.

Returns
Boolean
loadItemPackData()method 
public function loadItemPackData(ident:String, onLoaded:Function, onFailure:Function):void

Loads the binary data for the item pack with the specified ident.

Parameters
ident:String — the identifier of the item pack to be loaded.
 
onLoaded:Function — a function with the signature: function (data :ByteArray) :void that will be called with the item pack data if it loads successfully.
 
onFailure:Function — a function with the signature: function (error :Error) :void that will be called if the pack loading fails.
loadLevelPackData()method 
public function loadLevelPackData(ident:String, onLoaded:Function, onFailure:Function):void

Loads the binary data for the level pack with the specified ident.

Parameters
ident:String — the identifier of the level pack to be loaded.
 
onLoaded:Function — a function with the signature: function (data :ByteArray) :void that will be called with the level pack data if it loads successfully.
 
onFailure:Function — a function with the signature: function (error :Error) :void that will be called if the pack loading fails.
playerReady()method 
public function playerReady():void

If the game was not configured to auto-start, which is determined by the 2nd parameter to the GameControl constructor, then all player clients must call this function to let the server know that they are ready, at which point the game will be started.

This method is also used for rematches: once a game has started and finished, all clients can call this function again to start a new game.

restartGameIn()method 
public function restartGameIn(seconds:int):void

Requests to start the game again in the specified number of seconds. This should only be used for party games. Seated table games (including single player games) should have each player report that they are ready again and the game will automatically start.

Parameters
seconds:int
startNextTurn()method 
public function startNextTurn(nextPlayerId:int = 0):void

Start the next player's turn. If a playerId is specified, that player's turn will be next. Otherwise the turn will be assigned randomly the first time, after that following the "natural" turn order. In a seated game, the natural order follows the seating order. In a party game, the natural order is to give the turn to the player that has been around the longest without getting a turn.

Parameters
nextPlayerId:int (default = 0)
systemMessage()method 
public function systemMessage(msg:String):void

Send a system chat message that will be seen by everyone in the game room, even observers.

Parameters
msg:String
takeOverPlayer()method 
public function takeOverPlayer(playerId:int):void

Tells the system that the server agent will take over for the specified player. If a game wishes the take over the control for a departed player to allow the other players to continue to play with an AI in that player's position or without the player entirely, this method can be used. Only call this method for players that have left the game.

Note: this method can only be called by the server agent. Parameters

playerId:int
Event detail
ControlChangedevent 
Event object type: com.whirled.game.StateChangedEvent
StateChangedEvent.type property = com.whirled.game.StateChangedEvent.CONTROL_CHANGED

Dispatched when the controller changes for the game.

Indicates that a new controller has been assigned.

GameEndedevent  
Event object type: com.whirled.game.StateChangedEvent
StateChangedEvent.type property = com.whirled.game.StateChangedEvent.GAME_ENDED

Dispatched when the game ends.

Indicates that the game has transitioned to a ended state.

GameStartedevent  
Event object type: com.whirled.game.StateChangedEvent
StateChangedEvent.type property = com.whirled.game.StateChangedEvent.GAME_STARTED

Dispatched when the game starts, usually after all players are present.

Indicates that the game has transitioned to a started state.

OccupantEnteredevent  
Event object type: com.whirled.game.OccupantChangedEvent
OccupantChangedEvent.type property = com.whirled.game.OccupantChangedEvent.OCCUPANT_ENTERED

Dispatched when an occupant enters the game.

OccupantLeftevent  
Event object type: com.whirled.game.OccupantChangedEvent
OccupantChangedEvent.type property = com.whirled.game.OccupantChangedEvent.OCCUPANT_LEFT

Dispatched when an occupant leaves the game.

partyEnteredevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.party.PartySubControl.PARTY_ENTERED

Dispatched when a party arrives in the game.

An event type dispatched on the GameSubControl when a party joins the game.
name - not used
value - partyId

partyLeftevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.party.PartySubControl.PARTY_LEFT

Dispatched when a party leaves the game.

An event type dispatched on the GameSubControl when a party leaves the game.
name - not used
value - partyId

RoundEndedevent  
Event object type: com.whirled.game.StateChangedEvent
StateChangedEvent.type property = com.whirled.game.StateChangedEvent.ROUND_ENDED

Dispatched when a round ends.

Indicates that the current round has ended.

RoundStartedevent  
Event object type: com.whirled.game.StateChangedEvent
StateChangedEvent.type property = com.whirled.game.StateChangedEvent.ROUND_STARTED

Dispatched when a round starts.

Indicates that a round has started. Games that do not require multiple rounds can ignore this event.

TurnChangedevent  
Event object type: com.whirled.game.StateChangedEvent
StateChangedEvent.type property = com.whirled.game.StateChangedEvent.TURN_CHANGED

Dispatched when the turn changes in a turn-based game.

Indicates that the turn has changed.

UserChatevent  
Event object type: com.whirled.game.UserChatEvent
UserChatEvent.type property = com.whirled.game.UserChatEvent.USER_CHAT

Dispatched when a user chats.

The type of a property change event.

Constant detail
CASCADING_PAYOUTconstant
public static const CASCADING_PAYOUT:int = 0

Cascading payout skews awards toward the winners by giving 50% of last place's payout to first place, 25% to the next inner pair of opponents (third to second in a four player game, for example), and so on. It is very similar overall to WINNERS_TAKE_ALL, only it rewards everyone at least a little bit.

PROPORTIONALconstant 
public static const PROPORTIONAL:int = 3

Proportional is used for games where there is no way to measure player's performance against a global standard, but where the scores are subjective to the particular players currently playing. Each player vies to get their score the highest, and the coins are split up according to the relative scores.

SERVER_AGENT_IDconstant 
public static const SERVER_AGENT_ID:int = -2.147483648E9

ID constant returned by getMyId when called by a game's server agent.

See also

TO_EACH_THEIR_OWNconstant 
public static const TO_EACH_THEIR_OWN:int = 2

Each player receives a payout based only on their score and not influenced by the scores of any other player.

WINNERS_TAKE_ALLconstant 
public static const WINNERS_TAKE_ALL:int = 1

Winner takes all splits the total coins available to award to all players in the game among those identified as winners at the end of the game. When used with endGameWithScores, it is intended for games where each player's performance is independant of the others and can be measured against a global standard. The winner(s) will get more coins if they beat someone else who played well than if they beat someone who played poorly. Using it with endGameWithWinners() is intended for games in which there is no per-player score, just some player(s) defeating others. In this case, the game is stating that it cannot distinguish between an excellent player and a poor player, just one won over the others.