Packageorg.flixel
Classpublic class FlxButton
InheritanceFlxButton Inheritance FlxGroup Inheritance FlxObject Inheritance FlxRect Inheritance FlxPoint

A simple button class that calls a function when clicked by the mouse. Supports labels, highlight states, and parallax scrolling.



Public Properties
 PropertyDefined by
 Inheritedacceleration : FlxPoint
How fast the speed of this object is changing.
FlxObject
 Inheritedactive : Boolean
If an object is not alive, the game loop will not automatically call update() on it.
FlxObject
 Inheritedangle : Number
Set the angle of a sprite to rotate it.
FlxObject
 InheritedangularAcceleration : Number
How fast the spin speed should change.
FlxObject
 InheritedangularDrag : Number
Like drag but for spinning.
FlxObject
 InheritedangularVelocity : Number
This is how fast you want this sprite to spin.
FlxObject
 Inheritedbottom : Number
The Y coordinate of the bottom of the rectangle.
FlxRect
 InheritedcolHullX : FlxRect
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
 InheritedcolHullY : FlxRect
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
 InheritedcollideBottom : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcollideLeft : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcollideRight : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcollideTop : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcolOffsets : Array
An array of FlxPoint objects.
FlxObject
 InheritedcolVector : FlxPoint
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
 Inheriteddead : Boolean
Handy for tracking gameplay or animations.
FlxObject
 Inheriteddrag : FlxPoint
This isn't drag exactly, more like deceleration that is only applied when acceleration is not affecting the sprite.
FlxObject
 Inheritedexists : Boolean
Kind of a global on/off switch for any objects descended from FlxObject.
FlxObject
 Inheritedfixed : Boolean
Set fixed to true if you want the object to stay in place during collisions.
FlxObject
 Inherited_group : Boolean
Dedicated internal flag for whether or not this class is a FlxGroup.
FlxObject
 Inheritedhealth : Number
Handy for storing health percentage or armor points or whatever.
FlxObject
 Inheritedheight : Number
FlxRect
 Inheritedleft : Number
The X coordinate of the left side of the rectangle.
FlxRect
 InheritedmaxAngular : Number
Use in conjunction with angularAcceleration for fluid spin speed control.
FlxObject
 InheritedmaxThrust : Number
Used to cap thrust, helpful and easy!
FlxObject
 InheritedmaxVelocity : FlxPoint
If you are using acceleration, you can use maxVelocity with it to cap the speed automatically (very useful!).
FlxObject
 Inheritedmembers : Array
Array of all the FlxObjects that exist in this layer.
FlxGroup
 Inheritedmoves : Boolean
Set this to false if you want to skip the automatic motion/movement stuff (see updateMotion()).
FlxObject
  on : Boolean
Use this to toggle checkbox-style behavior.
FlxButton
 InheritedonFloor : Boolean
Flag that indicates whether or not you just hit the floor.
FlxObject
 Inheritedorigin : FlxPoint
WARNING: The origin of the sprite will default to its center.
FlxObject
  pauseProof : Boolean
Set this to true if you want this button to function even while the game is paused.
FlxButton
 Inheritedright : Number
The X coordinate of the right side of the rectangle.
FlxRect
 InheritedscrollFactor : FlxPoint
A point that can store numbers from 0 to 1 (for X and Y independently) that governs how much this object is affected by the camera subsystem.
FlxObject
 Inheritedsolid : Boolean
Set solid to true if you want to collide this object.
FlxObject
 Inheritedthrust : Number
If you want to do Asteroids style stuff, check out thrust, instead of directly accessing the object's velocity or acceleration.
FlxObject
 Inheritedtop : Number
The Y coordinate of the top of the rectangle.
FlxRect
 Inheritedvelocity : FlxPoint
The basic speed of this object.
FlxObject
 Inheritedvisible : Boolean
If an object is not visible, the game loop will not automatically call render() on it.
FlxObject
 Inheritedwidth : Number
FlxRect
 Inheritedx : Number
FlxPoint
 Inheritedy : Number
FlxPoint
Protected Properties
 PropertyDefined by
  _callback : Function
This function is called when the button is clicked.
FlxButton
 Inherited_first : Boolean
FlxGroup
 Inherited_fixed : Boolean
Internal tracker for whether an object will move/alter position after a collision (see fixed).
FlxObject
 Inherited_flashPoint : Point
This is a pre-allocated Flash Point object, which is useful for certain Flash graphics API calls
FlxObject
 Inherited_flicker : Boolean
Internal helper used for retro-style flickering.
FlxObject
 Inherited_flickerTimer : Number
Internal helper used for retro-style flickering.
FlxObject
  _initialized : Boolean
Whether or not the button has initialized itself yet.
FlxButton
 Inherited_last : FlxPoint
Helpers for moving/updating group members.
FlxGroup
  _off : FlxSprite
Stores the 'off' or normal button state graphic.
FlxButton
  _offT : FlxText
Stores the 'off' or normal button state label.
FlxButton
  _on : FlxSprite
Stores the 'on' or highlighted button state graphic.
FlxButton
  _onT : FlxText
Stores the 'on' or highlighted button state label.
FlxButton
  _onToggle : Boolean
Used for checkbox-style behavior.
FlxButton
 Inherited_point : FlxPoint
This is just a pre-allocated x-y point container to be used however you like
FlxObject
  _pressed : Boolean
Tracks whether or not the button is currently pressed.
FlxButton
 Inherited_rect : FlxRect
This is just a pre-allocated rectangle container to be used however you like
FlxObject
  _sf : FlxPoint
Helper variable for correcting its members' scrollFactor objects.
FlxButton
 Inherited_solid : Boolean
Internal tracker for whether or not the object collides (see solid).
FlxObject
 Inherited_sortIndex : String
Helpers for sorting members.
FlxGroup
 Inherited_sortOrder : int
FlxGroup
Public Methods
 MethodDefined by
  
FlxButton(X:int, Y:int, Callback:Function)
Creates a new FlxButton object with a gray background and a callback function on the UI thread.
FlxButton
 Inherited
add(Object:FlxObject, ShareScroll:Boolean = false):FlxObject
Adds a new FlxObject subclass (FlxSprite, FlxBlock, etc) to the list of children
FlxGroup
 Inherited
collide(Object:FlxObject = null):Boolean
If you don't want to call FlxU.collide() you can use this instead.
FlxObject
 Inherited
countDead():int
Call this function to find out how many members of the group are dead.
FlxGroup
 Inherited
Call this function to find out how many members of the group are not dead.
FlxGroup
 Inherited
Returns a count of how many objects in this group are on-screen right now.
FlxGroup
  
destroy():void
Called by the game state when state is changed (if this object belongs to the state)
FlxButton
 Inherited
flicker(Duration:Number = 1):void
Tells this object to flicker, retro-style.
FlxObject
 Inherited
flickering():Boolean
Check to see if the object is still flickering.
FlxObject
 Inherited
Returns the appropriate color for the bounding box depending on object state.
FlxObject
 Inherited
Call this function to retrieve the first object with dead == false in the group.
FlxGroup
 Inherited
Call this function to retrieve the first object with exists == false in the group.
FlxGroup
 Inherited
Call this function to retrieve the first object with dead == true in the group.
FlxGroup
 Inherited
Call this function to retrieve the first object with exists == true in the group.
FlxGroup
 Inherited
Call this function to retrieve the first index set to 'null'.
FlxGroup
 Inherited
Returns a member at random from the group.
FlxGroup
 Inherited
getScreenXY(Point:FlxPoint = null):FlxPoint
Call this function to figure out the on-screen position of the object.
FlxObject
 Inherited
hitBottom(Contact:FlxObject, Velocity:Number):void
Called when this object's bottom edge collides with the top of another FlxObject.
FlxObject
 Inherited
hitLeft(Contact:FlxObject, Velocity:Number):void
Called when this object's left side collides with another FlxObject's right.
FlxObject
 Inherited
hitRight(Contact:FlxObject, Velocity:Number):void
Called when this object's right side collides with another FlxObject's left.
FlxObject
 Inherited
hitSide(Contact:FlxObject, Velocity:Number):void
Since most games have identical behavior for running into walls, you can just override this function instead of overriding both hitLeft and hitRight.
FlxObject
 Inherited
hitTop(Contact:FlxObject, Velocity:Number):void
Called when this object's top collides with the bottom of another FlxObject.
FlxObject
 Inherited
hurt(Damage:Number):void
Call this function to "damage" (or give health bonus) to this sprite.
FlxObject
 Inherited
kill():void
Calls kill on the group and all its members.
FlxGroup
  
loadGraphic(Image:FlxSprite, ImageHighlight:FlxSprite = null):FlxButton
Set your own image as the button background.
FlxButton
  
loadText(Text:FlxText, TextHighlight:FlxText = null):FlxButton
Add a text label to the button.
FlxButton
 Inherited
onScreen():Boolean
Check and see if this object is currently on screen.
FlxObject
 Inherited
overlaps(Object:FlxObject):Boolean
Checks to see if some FlxObject object overlaps this FlxObject object.
FlxObject
 Inherited
overlapsPoint(X:Number, Y:Number, PerPixel:Boolean = false):Boolean
Checks to see if a point in 2D space overlaps this FlxObject object.
FlxObject
 Inherited
preCollide(Object:FlxObject):void
FlxU.collide() (and thus FlxObject.collide()) call this function each time two objects are compared to see if they collide.
FlxObject
 Inherited
refreshHulls():void
Called by FlxObject.updateMotion() and some constructors to rebuild the basic collision data for this object.
FlxObject
 Inherited
remove(Object:FlxObject, Splice:Boolean = false):FlxObject
Removes an object from the group.
FlxGroup
 Inherited
render():void
Automatically goes through and calls render on everything you added, override this loop to control render order manually.
FlxGroup
 Inherited
replace(OldObject:FlxObject, NewObject:FlxObject):FlxObject
Replaces an existing FlxObject with a new one.
FlxGroup
 Inherited
reset(X:Number, Y:Number):void
If the group's position is reset, we want to reset all its members too.
FlxGroup
 Inherited
resetFirstAvail(X:Number = 0, Y:Number = 0):Boolean
Finds the first object with exists == false and calls reset on it.
FlxGroup
 Inherited
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.
FlxPoint
  
update():void
Called by the game loop automatically, handles mouseover and click detection.
FlxButton
Protected Methods
 MethodDefined by
 Inherited
Internal function that actually loops through and destroys each member.
FlxGroup
 Inherited
killMembers():void
Internal function that calls kill on all members.
FlxGroup
  
onMouseUp(event:MouseEvent):void
Internal function for handling the actual callback call (for UI thread dependent calls like FlxU.openURL()).
FlxButton
 Inherited
Internal function that actually loops through and renders all the group members.
FlxGroup
 Inherited
Internal function, helps with the moving/updating of group members.
FlxGroup
 Inherited
Helper function for the sort process.
FlxGroup
 Inherited
Just updates the retro-style flickering.
FlxObject
 Inherited
Internal function that actually goes through and updates all the group members.
FlxGroup
 Inherited
updateMotion():void
Internal function for updating the position and speed of this object.
FlxObject
  
visibility(On:Boolean):void
Internal function for handling the visibility of the off and on graphics.
FlxButton
Public Constants
 ConstantDefined by
 InheritedASCENDING : int = -1
[static]
FlxGroup
 InheritedDESCENDING : int = 1
[static]
FlxGroup
Protected Constants
 ConstantDefined by
 Inherited_pZero : FlxPoint
[static] A handy "empty point" object
FlxObject
Property detail
_callbackproperty
protected var _callback:Function

This function is called when the button is clicked.

_initializedproperty 
protected var _initialized:Boolean

Whether or not the button has initialized itself yet.

_offproperty 
protected var _off:FlxSprite

Stores the 'off' or normal button state graphic.

_offTproperty 
protected var _offT:FlxText

Stores the 'off' or normal button state label.

_onproperty 
protected var _on:FlxSprite

Stores the 'on' or highlighted button state graphic.

onproperty 
on:Boolean  [read-write]

Use this to toggle checkbox-style behavior.

Implementation
    public function get on():Boolean
    public function set on(value:Boolean):void
_onTproperty 
protected var _onT:FlxText

Stores the 'on' or highlighted button state label.

_onToggleproperty 
protected var _onToggle:Boolean

Used for checkbox-style behavior.

pauseProofproperty 
public var pauseProof:Boolean

Set this to true if you want this button to function even while the game is paused.

_pressedproperty 
protected var _pressed:Boolean

Tracks whether or not the button is currently pressed.

_sfproperty 
protected var _sf:FlxPoint

Helper variable for correcting its members' scrollFactor objects.

Constructor detail
FlxButton()constructor
public function FlxButton(X:int, Y:int, Callback:Function)

Creates a new FlxButton object with a gray background and a callback function on the UI thread.

Parameters
X:int — The X position of the button.
 
Y:int — The Y position of the button.
 
Callback:Function — The function to call whenever the button is clicked.
Method detail
destroy()method
public override function destroy():void

Called by the game state when state is changed (if this object belongs to the state)

loadGraphic()method 
public function loadGraphic(Image:FlxSprite, ImageHighlight:FlxSprite = null):FlxButton

Set your own image as the button background.

Parameters
Image:FlxSprite — A FlxSprite object to use for the button background.
 
ImageHighlight:FlxSprite (default = null) — A FlxSprite object to use for the button background when highlighted (optional).

Returns
FlxButton — This FlxButton instance (nice for chaining stuff together, if you're into that).
loadText()method 
public function loadText(Text:FlxText, TextHighlight:FlxText = null):FlxButton

Add a text label to the button.

Parameters
Text:FlxText — A FlxText object to use to display text on this button (optional).
 
TextHighlight:FlxText (default = null) — A FlxText object that is used when the button is highlighted (optional).

Returns
FlxButton — This FlxButton instance (nice for chaining stuff together, if you're into that).
onMouseUp()method 
protected function onMouseUp(event:MouseEvent):void

Internal function for handling the actual callback call (for UI thread dependent calls like FlxU.openURL()).

Parameters
event:MouseEvent
update()method 
public override function update():void

Called by the game loop automatically, handles mouseover and click detection.

visibility()method 
protected function visibility(On:Boolean):void

Internal function for handling the visibility of the off and on graphics.

Parameters
On:Boolean — Whether the button should be on or off.