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
 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?
FlxBasic
  length : Number
FlxGroup
  maxSize : uint
FlxGroup
  members : Array
Array of all the FlxBasics that exist in this layer.
FlxGroup
 Inheritedvisible : Boolean
Controls whether draw() is automatically called by FlxState/FlxGroup.
FlxBasic
 Inherited_VISIBLECOUNT : uint
[static]
FlxBasic
Protected Properties
 PropertyDefined By
  _marker : uint
FlxGroup
  _maxSize : uint
FlxGroup
  _sortIndex : String
Helpers for sorting members.
FlxGroup
  _sortOrder : int
FlxGroup
Public Methods
 MethodDefined By
  
FlxGroup(MaxSize:uint = 0)
Constructor
FlxGroup
  
Adds a new FlxBasic subclass (FlxBasic, FlxSprite, MyEnemy, etc) to 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, override this loop to control render order manually.
FlxGroup
  
Call this function to retrieve the first object with dead == false in the group.
FlxGroup
  
getFirstAvail(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
  
Returns a member at random from the group.
FlxGroup
  
kill():void
[override] Calls kill on the group and all its members.
FlxGroup
 Inherited
onScreen(Camera:FlxCamera = null):Boolean
FlxBasic
 Inherited
postUpdate():void
FlxBasic
  
preUpdate():void
[override]
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
FlxBasic
  
setAll(VariableName:String, Value:Object, Recurse:Boolean = true):void
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, override this function to handle custom input and perform collisions.
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]
FlxGroup
  DESCENDING : int = 1
[static]
FlxGroup
  GROW : uint = 1
[static]
FlxGroup
  STRICT : uint = 0
[static]
FlxGroup
Property Detail
_markerproperty
protected var _marker:uint

_maxSizeproperty 
protected var _maxSize:uint

_sortIndexproperty 
protected var _sortIndex:String

Helpers for sorting members.

_sortOrderproperty 
protected var _sortOrder:int

lengthproperty 
public var length:Number

maxSizeproperty 
maxSize:uint


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 layer.

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, MyEnemy, 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.
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, override this loop to control render order manually.

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.
getFirstAvail()method 
public function getFirstAvail(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():FlxBasic

Returns a member at random from the group.

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

Calls kill on the group and all its members.

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

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

Parameters

VariableName:String
 
Value:Object
 
Recurse:Boolean (default = true)

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, override this function to handle custom input and perform collisions.

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

DESCENDINGConstant 
public static const DESCENDING:int = 1

GROWConstant 
public static const GROW:uint = 1

STRICTConstant 
public static const STRICT:uint = 0