Packagecom.whirled.game
Classpublic class BagsSubControl
InheritanceBagsSubControl Inheritance AbstractSubControl Inheritance AbstractControl Inheritance flash.events.EventDispatcher

Contains 'bags' game services. Do not instantiate this class yourself, access it via GameControl.services.bags. Bags are secret collections containing non-unique elements that are stored on the server. They can be used to implement game features where clients can't be trusted to not sniff their network. For example you could create a bag called "dice" and fill it with [ 1, 2, 3, 4, 5, 6 ]. Now you can roll the die with _ctrl.services.bags.pick("dice", 1, "diceProperty");



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
  
addTo(bagName:String, values:Array):void
Add values to an existing bag.
BagsSubControl
  
create(bagName:String, values:Array):void
Create a bag containing the specified values, clearing any previous bag with the same name.
BagsSubControl
  
deal(bagName:String, count:int, msgOrPropName:String, callback:Function = null, playerId:int):void
Deal (remove) the specified number of elements from a bag, and distribute them to a specific player or set them as a property in the game data.
BagsSubControl
 Inherited
doBatch(fn:Function, ... args):void
Execute the specified function as a batch of commands that will be sent to the server together.
AbstractSubControl
 Inherited
isConnected():Boolean
Are we connected and running inside the whirled environment, or has someone just loaded up our SWF by itself?
AbstractSubControl
  
merge(srcBag:String, intoBag:String):void
Merge all values from the specified bag into the other bag.
BagsSubControl
  
pick(bagName:String, count:int, msgOrPropName:String, playerId:int):void
Pick (do not remove) the specified number of elements from a bag, and distribute them to a specific player or set them as a property in the game data.
BagsSubControl
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Unregisters an event listener.
AbstractControl
Events
 EventSummaryDefined by
 Inherited Event.UNLOAD Dispatched when the SWF using this control has been unloaded.AbstractControl
Public Constants
 ConstantDefined by
  SHOW_TO_ALL : int = 0
[static] Player id constant used by pick and deal indicating that elements should be picked or dealt publicly to all players.
BagsSubControl
Method detail
addTo()method
public function addTo(bagName:String, values:Array):void

Add values to an existing bag. If it doesn't exist, it will be created.

Parameters
bagName:String
 
values:Array
create()method 
public function create(bagName:String, values:Array):void

Create a bag containing the specified values, clearing any previous bag with the same name.

Parameters
bagName:String
 
values:Array
deal()method 
public function deal(bagName:String, count:int, msgOrPropName:String, callback:Function = null, playerId:int):void

Deal (remove) the specified number of elements from a bag, and distribute them to a specific player or set them as a property in the game data. Fails if the named collection could not be found or does not contain enough elements to complete the deal.

Parameters
bagName:String — the collection name.
 
count:int — the number of elements to pick
 
msgOrPropName:String — the name of the message or property that will contain the picked elements.
 
callback:Function (default = null) — optional function to call after the deal has completed. If provided, the signature of the function must be compatible with the following:
             function onDealt (count :int) :void {}
         
If the deal fails for any reason, the count will be 0, otherwise it will be the number of elements dealt.
 
playerId:int — if SHOW_TO_ALL (or unset), the picked elements should be set on the gameObject as a property for all to see. If a playerId is specified, only that player will receive the elements as a message.

See also

merge()method 
public function merge(srcBag:String, intoBag:String):void

Merge all values from the specified bag into the other bag. The source bag will be destroyed. The elements from the source bag will be shuffled and appended to the end of the destination bag.

Parameters
srcBag:String
 
intoBag:String
pick()method 
public function pick(bagName:String, count:int, msgOrPropName:String, playerId:int):void

Pick (do not remove) the specified number of elements from a bag, and distribute them to a specific player or set them as a property in the game data.

Parameters
bagName:String — the collection name.
 
count:int — the number of elements to pick
 
msgOrPropName:String — the name of the message or property that will contain the picked elements.
 
playerId:int — if SHOW_TO_ALL (or unset), the picked elements should be set on the gameObject as a property for all to see. If a playerId is specified, only that player will receive the elements as a message.

See also

Constant detail
SHOW_TO_ALLconstant
public static const SHOW_TO_ALL:int = 0

Player id constant used by pick and deal indicating that elements should be picked or dealt publicly to all players.

See also