Packageorg.flixel
Classpublic class FlxGroup
InheritanceFlxGroup Inheritance FlxBasic Inheritance Object
Subclasses FlxEmitter, FlxState

This is an organizational class that can update and render a bunch of FlxBasics. NOTE: Although FlxGroup extends FlxBasic, it will not automatically add itself to the global collisions quad tree, it will only add its members.



Public Properties
 PropertyDefined By
 Inheritedactive : Boolean
Controls whether update() is automatically called by FlxState/FlxGroup.
FlxBasic
 Inherited_ACTIVECOUNT : uint
[static]
FlxBasic
 Inheritedalive : Boolean
Useful state for many game objects - "dead" (!alive) vs alive.
FlxBasic
 Inheritedcameras : Array
An array of camera objects that this object will use during draw().
FlxBasic
 Inheritedexists : Boolean
Controls whether update() and draw() are automatically called by FlxState/FlxGroup.
FlxBasic
 InheritedID : int
IDs seem like they could be pretty useful, huh? They're not actually used for anything yet though.
FlxBasic
 InheritedignoreDrawDebug : Boolean
Setting this to true will prevent the object from appearing when the visual debug mode in the debugger overlay is toggled on.
FlxBasic
  length : Number
The number of entries in the members array.
FlxGroup
  maxSize : uint
The maximum capacity of this group.
FlxGroup
  members : Array
Array of all the FlxBasics that exist in this group.
FlxGroup
 Inheritedvisible : Boolean
Controls whether draw() is automatically called by FlxState/FlxGroup.
FlxBasic
 Inherited_VISIBLECOUNT : uint
[static]
FlxBasic
Protected Properties
 PropertyDefined By
  _marker : uint
Internal helper variable for recycling objects a la FlxEmitter.
FlxGroup
  _maxSize : uint
Internal tracker for the maximum capacity of the group.
FlxGroup
  _sortIndex : String
Helper for sort.
FlxGroup
  _sortOrder : int
Helper for sort.
FlxGroup
Public Methods
 MethodDefined By
  
FlxGroup(MaxSize:uint = 0)
Constructor
FlxGroup
  
Adds a new FlxBasic subclass (FlxBasic, FlxSprite, Enemy, etc) to the group.
FlxGroup
  
callAll(FunctionName:String, Recurse:Boolean = true):void
Go through and call the specified function on all members of the group.
FlxGroup
  
clear():void
Remove all instances of FlxBasic subclass (FlxSprite, FlxBlock, etc) from the list.
FlxGroup
  
countDead():int
Call this function to find out how many members of the group are dead.
FlxGroup
  
Call this function to find out how many members of the group are not dead.
FlxGroup
  
destroy():void
[override] Override this function to handle any deleting or "shutdown" type operations you might need, such as removing traditional Flash children like Sprite objects.
FlxGroup
  
draw():void
[override] Automatically goes through and calls render on everything you added.
FlxGroup
 Inherited
drawDebug(Camera:FlxCamera = null):void
Override this function to draw custom "debug mode" graphics to the specified camera while the debugger's visual mode is toggled on.
FlxBasic
  
Call this function to retrieve the first object with dead == false in the group.
FlxGroup
  
getFirstAvailable(ObjectClass:Class = null):FlxBasic
Call this function to retrieve the first object with exists == false in the group.
FlxGroup
  
Call this function to retrieve the first object with dead == true in the group.
FlxGroup
  
Call this function to retrieve the first object with exists == true in the group.
FlxGroup
  
Call this function to retrieve the first index set to 'null'.
FlxGroup
  
getRandom(StartIndex:uint = 0, Length:uint = 0):FlxBasic
Returns a member at random from the group.
FlxGroup
  
kill():void
[override] Calls kill on the group's members and then on the group itself.
FlxGroup
 Inherited
postUpdate():void
Post-update is called right after update() on each object in the game loop.
FlxBasic
  
preUpdate():void
[override] Just making sure we don't increment the active objects count.
FlxGroup
  
recycle(ObjectClass:Class = null):FlxBasic
Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
FlxGroup
  
remove(Object:FlxBasic, Splice:Boolean = false):FlxBasic
Removes an object from the group.
FlxGroup
  
replace(OldObject:FlxBasic, NewObject:FlxBasic):FlxBasic
Replaces an existing FlxBasic with a new one.
FlxGroup
 Inherited
revive():void
Handy function for bringing game objects "back to life".
FlxBasic
  
setAll(VariableName:String, Value:Object, Recurse:Boolean = true):void
Go through and set the specified variable to the specified value on all members of the group.
FlxGroup
  
sort(Index:String = y, Order:int):void
Call this function to sort the group according to a particular value and order.
FlxGroup
 Inherited
toString():String
Convert object to readable string name.
FlxBasic
  
update():void
[override] Automatically goes through and calls update on everything you added.
FlxGroup
Protected Methods
 MethodDefined By
  
sortHandler(Obj1:FlxBasic, Obj2:FlxBasic):int
Helper function for the sort process.
FlxGroup
Public Constants
 ConstantDefined By
  ASCENDING : int = -1
[static] Use with sort() to sort in ascending order.
FlxGroup
  DESCENDING : int = 1
[static] Use with sort() to sort in descending order.
FlxGroup
Property Detail
_markerproperty
protected var _marker:uint

Internal helper variable for recycling objects a la FlxEmitter.

_maxSizeproperty 
protected var _maxSize:uint

Internal tracker for the maximum capacity of the group. Default is 0, or no max capacity.

_sortIndexproperty 
protected var _sortIndex:String

Helper for sort.

_sortOrderproperty 
protected var _sortOrder:int

Helper for sort.

lengthproperty 
public var length:Number

The number of entries in the members array. For performance and safety you should check this variable instead of members.length unless you really know what you're doing!

maxSizeproperty 
maxSize:uint

The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.


Implementation
    public function get maxSize():uint
    public function set maxSize(value:uint):void
membersproperty 
public var members:Array

Array of all the FlxBasics that exist in this group.

Constructor Detail
FlxGroup()Constructor
public function FlxGroup(MaxSize:uint = 0)

Constructor

Parameters
MaxSize:uint (default = 0)
Method Detail
add()method
public function add(Object:FlxBasic):FlxBasic

Adds a new FlxBasic subclass (FlxBasic, FlxSprite, Enemy, etc) to the group. FlxGroup will try to replace a null member of the array first. Failing that, FlxGroup will add it to the end of the member array, assuming there is room for it, and doubling the size of the array if necessary.

WARNING: If the group has a maxSize that has already been met, the object will NOT be added to the group!

Parameters

Object:FlxBasic — The object you want to add to the group.

Returns
FlxBasic — The same FlxBasic object that was passed in.
callAll()method 
public function callAll(FunctionName:String, Recurse:Boolean = true):void

Go through and call the specified function on all members of the group. Currently only works on functions that have no required parameters.

Parameters

FunctionName:String — The string representation of the function you want to call on each object, for example "kill()" or "init()".
 
Recurse:Boolean (default = true) — Default value is true, meaning if callAll() encounters a member that is a group, it will call callAll() on that group rather than calling the group's function.

clear()method 
public function clear():void

Remove all instances of FlxBasic subclass (FlxSprite, FlxBlock, etc) from the list. WARNING: does not destroy() or kill() any of these objects!

countDead()method 
public function countDead():int

Call this function to find out how many members of the group are dead.

Returns
int — The number of FlxBasics flagged as dead. Returns -1 if group is empty.
countLiving()method 
public function countLiving():int

Call this function to find out how many members of the group are not dead.

Returns
int — The number of FlxBasics flagged as not dead. Returns -1 if group is empty.
destroy()method 
override public function destroy():void

Override this function to handle any deleting or "shutdown" type operations you might need, such as removing traditional Flash children like Sprite objects.

draw()method 
override public function draw():void

Automatically goes through and calls render on everything you added.

getFirstAlive()method 
public function getFirstAlive():FlxBasic

Call this function to retrieve the first object with dead == false in the group. This is handy for checking if everything's wiped out, or choosing a squad leader, etc.

Returns
FlxBasic — A FlxBasic currently flagged as not dead.
getFirstAvailable()method 
public function getFirstAvailable(ObjectClass:Class = null):FlxBasic

Call this function to retrieve the first object with exists == false in the group. This is handy for recycling in general, e.g. respawning enemies.

Parameters

ObjectClass:Class (default = null) — An optional parameter that lets you narrow the results to instances of this particular class.

Returns
FlxBasic — A FlxBasic currently flagged as not existing.
getFirstDead()method 
public function getFirstDead():FlxBasic

Call this function to retrieve the first object with dead == true in the group. This is handy for checking if everything's wiped out, or choosing a squad leader, etc.

Returns
FlxBasic — A FlxBasic currently flagged as dead.
getFirstExtant()method 
public function getFirstExtant():FlxBasic

Call this function to retrieve the first object with exists == true in the group. This is handy for checking if everything's wiped out, or choosing a squad leader, etc.

Returns
FlxBasic — A FlxBasic currently flagged as existing.
getFirstNull()method 
public function getFirstNull():int

Call this function to retrieve the first index set to 'null'. Returns -1 if no index stores a null object.

Returns
int — An int indicating the first null slot in the group.
getRandom()method 
public function getRandom(StartIndex:uint = 0, Length:uint = 0):FlxBasic

Returns a member at random from the group.

Parameters

StartIndex:uint (default = 0) — Optional offset off the front of the array. Default value is 0, or the beginning of the array.
 
Length:uint (default = 0) — Optional restriction on the number of values you want to randomly select from.

Returns
FlxBasic — A FlxBasic from the members list.
kill()method 
override public function kill():void

Calls kill on the group's members and then on the group itself.

preUpdate()method 
override public function preUpdate():void

Just making sure we don't increment the active objects count.

recycle()method 
public function recycle(ObjectClass:Class = null):FlxBasic

Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.

If you specified a maximum size for this group (like in FlxEmitter), then recycle will employ what we're calling "rotating" recycling. Recycle() will first check to see if the group is at capacity yet. If group is not yet at capacity, recycle() returns a new object. If the group IS at capacity, then recycle() just returns the next object in line.

If you did NOT specify a maximum size for this group, then recycle() will employ what we're calling "grow-style" recycling. Recycle() will return either the first object with exists == false, or, finding none, add a new object to the array, doubling the size of the array if necessary.

WARNING: If this function needs to create a new object, and no object class was provided, it will return null instead of a valid object!

Parameters

ObjectClass:Class (default = null) — The class type you want to recycle (e.g. FlxSprite, EvilRobot, etc). Do NOT "new" the class in the parameter!

Returns
FlxBasic — A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;).
remove()method 
public function remove(Object:FlxBasic, Splice:Boolean = false):FlxBasic

Removes an object from the group.

Parameters

Object:FlxBasic — The FlxBasic you want to remove.
 
Splice:Boolean (default = false) — Whether the object should be cut from the array entirely or not.

Returns
FlxBasic — The removed object.
replace()method 
public function replace(OldObject:FlxBasic, NewObject:FlxBasic):FlxBasic

Replaces an existing FlxBasic with a new one.

Parameters

OldObject:FlxBasic — The object you want to replace.
 
NewObject:FlxBasic — The new object you want to use instead.

Returns
FlxBasic — The new object.
setAll()method 
public function setAll(VariableName:String, Value:Object, Recurse:Boolean = true):void

Go through and set the specified variable to the specified value on all members of the group.

Parameters

VariableName:String — The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
 
Value:Object — The value you want to assign to that variable.
 
Recurse:Boolean (default = true) — Default value is true, meaning if setAll() encounters a member that is a group, it will call setAll() on that group rather than modifying its variable.

sort()method 
public function sort(Index:String = y, Order:int):void

Call this function to sort the group according to a particular value and order. For example, to sort game objects for Zelda-style overlaps you might call myGroup.sort("y",ASCENDING) at the bottom of your FlxState.update() override. To sort all existing objects after a big explosion or bomb attack, you might call myGroup.sort("exists",DESCENDING).

Parameters

Index:String (default = y) — The String name of the member variable you want to sort on. Default value is "y".
 
Order:int (default = NaN) — A FlxGroup constant that defines the sort order. Possible values are ASCENDING and DESCENDING. Default value is ASCENDING.

sortHandler()method 
protected function sortHandler(Obj1:FlxBasic, Obj2:FlxBasic):int

Helper function for the sort process.

Parameters

Obj1:FlxBasic — The first object being sorted.
 
Obj2:FlxBasic — The second object being sorted.

Returns
int — An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
update()method 
override public function update():void

Automatically goes through and calls update on everything you added.

Constant Detail
ASCENDINGConstant
public static const ASCENDING:int = -1

Use with sort() to sort in ascending order.

DESCENDINGConstant 
public static const DESCENDING:int = 1

Use with sort() to sort in descending order.