class Button
package feathers.controls
extends BasicButton › FeathersControl › MeasureSprite › ValidatingSprite
implements IFocusObject, ITextControl
A push button control that may be triggered when pressed and released.
The following example creates a button, gives it a label and listens for when the button is triggered:
var button = new Button();
button.text = "Click Me";
button.addEventListener(TriggerEvent.TRIGGER, (event) -> {
trace("button triggered!");
});
this.addChild(button);
1.0.0
.See also:
Constructor
Variables
embedFonts:Bool = false
Determines if an embedded font is used or not.
In the following example, the button uses embedded fonts:
button.embedFonts = true;
1.0.0
.See also:
gap:Float = 0.0
The space, measured in pixels, between the button's icon and its text.
Applies to either horizontal or vertical spacing, depending on the value
of iconPosition
.
If the gap
is set to Math.POSITIVE_INFINITY
, the icon and the text
will be positioned as far apart as possible. In other words, they will
be positioned at the edges of the button (adjusted for padding).
The following example creates a gap of 20 pixels between the icon and the text:
button.text = "Click Me";
button.icon = new Bitmap(bitmapData);
button.gap = 20.0;
1.0.0
.See also:
horizontalAlign:HorizontalAlign = CENTER
How the content is positioned horizontally (along the x-axis) within the button.
The following example aligns the button's content to the left:
button.verticalAlign = LEFT;
Note: The HorizontalAlign.JUSTIFY
constant is not supported by this
component.
See also:
icon:DisplayObject = null
The display object to use as the button's icon.
To render a different icon depending on the button's current state,
pass additional icons to setIconForState()
.
The following example gives the button an icon:
button.icon = new Bitmap(bitmapData);
To change the position of the icon relative to the button's text, see
iconPosition
and gap
.
button.icon = new Bitmap(bitmapData);
button.iconPosition = RIGHT;
button.gap = 20.0;
1.0.0
.See also:
iconPosition:RelativePosition = LEFT
The location of the button's icon, relative to its text.
The following example positions the icon to the right of the text:
button.text = "Click Me";
button.icon = new Bitmap(texture);
button.iconPosition = RIGHT;
1.0.0
.See also:
minGap:Float = 0.0
If the value of the gap
property is Math.POSITIVE_INFINITY
, meaning
that the gap will fill as much space as possible and position the icon
and text on the edges of the button, the final calculated value of the
gap will not be smaller than the value of the minGap
property.
The following example ensures that the gap is never smaller than 20 pixels:
button.gap = Math.POSITIVE_INFINITY;
button.minGap = 20.0;
1.0.0
.See also:
paddingBottom:Float = 0.0
The minimum space, in pixels, between the button's bottom edge and the button's content.
In the following example, the button's bottom padding is set to 20 pixels:
button.paddingBottom = 20.0;
1.0.0
.paddingLeft:Float = 0.0
The minimum space, in pixels, between the button's left edge and the button's content.
In the following example, the button's left padding is set to 20 pixels:
button.paddingLeft = 20.0;
1.0.0
.paddingRight:Float = 0.0
The minimum space, in pixels, between the button's right edge and the button's content.
In the following example, the button's right padding is set to 20 pixels:
button.paddingRight = 20.0;
1.0.0
.paddingTop:Float = 0.0
The minimum space, in pixels, between the button's top edge and the button's content.
In the following example, the button's top padding is set to 20 pixels:
button.paddingTop = 20.0;
1.0.0
.text:String
The text displayed by the button.
The following example sets the button's text:
button.text = "Click Me";
1.0.0
.See also:
textFormat:TextFormat = null
The font styles used to render the button's text.
In the following example, the button's text formatting is customized:
button.textFormat = new TextFormat("Helvetica", 20, 0xcc0000);
1.0.0
.See also:
verticalAlign:VerticalAlign = MIDDLE
How the content is positioned vertically (along the y-axis) within the button.
The following example aligns the button's content to the top:
button.verticalAlign = TOP;
Note: The VerticalAlign.JUSTIFY
constant is not supported by this
component.
See also:
Methods
getIconForState(state:ButtonState):DisplayObject
Gets the icon to be used by the button when its currentState
property
matches the specified state value.
If an icon is not defined for a specific state, returns null
.
1.0.0
.See also:
getTextFormatForState(state:ButtonState):TextFormat
Gets the text format to be used by the button when its currentState
property matches the specified state value.
If a text format is not defined for a specific state, returns null
.
1.0.0
.See also:
setIconForState(state:ButtonState, icon:DisplayObject):Void
Set the icon to be used by the button when its currentState
property
matches the specified state value.
If an icon is not defined for a specific state, the value of the
textFormat
property will be used instead.
1.0.0
.See also:
setTextFormatForState(state:ButtonState, textFormat:TextFormat):Void
Set the text format to be used by the button when its currentState
property matches the specified state value.
If a text format is not defined for a specific state, the value of the
textFormat
property will be used instead.
1.0.0
.See also: