class Button
package feathers.controls
extends BasicButton › FeathersControl › MeasureSprite › ValidatingSprite
implements IFocusObject, IHTMLTextControl, 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:
Static variables
staticfinalread onlyVARIANT_DANGER:String = "danger"
A variant used to style the button in a style that indicates that performing the action is considered dangerous. Variants allow themes to provide an assortment of different appearances for the same type of UI component.
The following example uses this variant:
var button = new Button();
button.variant = Button.VARIANT_DANGER;
1.0.0
.See also:
staticfinalread onlyVARIANT_PRIMARY:String = "primary"
A variant used to style the button in a more prominent style to indicate its greater importance than other nearby buttons. Variants allow themes to provide an assortment of different appearances for the same type of UI component.
The following example uses this variant:
var button = new Button();
button.variant = Button.VARIANT_PRIMARY;
1.0.0
.See also:
staticfinalread onlyVARIANT_QUIET:String = "quiet"
A variant used to style the button in a less prominent style — typically hiding the background skin until interaction. Variants allow themes to provide an assortment of different appearances for the same type of UI component.
The following example uses this variant:
var button = new Button();
button.variant = Button.VARIANT_QUIET;
1.4.0
.See also:
Constructor
new(?text:String, ?triggerListener:TriggerEvent ‑> Void)
Creates a new Button
object.
1.0.0
.Variables
disabledTextFormat:AbstractTextFormat
The font styles used to render the button's text when the button is disabled.
In the following example, the button's disabled text formatting is customized:
button.enabled = false;
button.disabledTextFormat = new TextFormat("Helvetica", 20, 0xee0000);
1.0.0
.See also:
embedFonts:Bool
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
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
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.
1.0.0
.See also:
htmlText:String
Text displayed by the button that is parsed as a simple form of HTML.
The following example sets the button's HTML text:
button.htmlText = "<b>Hello</b> <i>World</i>";
1.0.0
.See also:
icon:DisplayObject
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:
iconOffsetX:Float
Offsets the x position of the icon by a certain number of pixels. This does not affect the measurement of the button. The button's width will not get smaller or larger when the icon is offset from its default x position.
The following example offsets the x position of the button's icon by 20 pixels:
button.iconOffsetX = 20.0;
1.0.0
.See also:
iconOffsetY:Float
Offsets the y position of the icon by a certain number of pixels. This does not affect the measurement of the button. The button's height will not get smaller or larger when the icon is offset from its default y position.
The following example offsets the y position of the button's icon by 20 pixels:
button.iconOffsetY = 20.0;
1.0.0
.See also:
iconPosition:RelativePosition
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
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
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
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
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
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
.showText:Bool
Shows or hides the button text. If the text is hidden, it will not affect the layout of other children, such as the icon.
1.0.0
.text:String
The text displayed by the button.
The following example sets the button's text:
button.text = "Click Me";
Note: If the htmlText
property is not null
, the text
property will
be ignored.
1.0.0
.See also:
textFormat:AbstractTextFormat
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:
textOffsetX:Float
Offsets the x position of the text by a certain number of pixels. This does not affect the measurement of the button. The button's width will not get smaller or larger when the text is offset from its default x position. Nor does it change the size of the text, so the text may appear outside of the button's bounds if the offset is large enough.
The following example offsets the x position of the button's text by 20 pixels:
button.textOffsetX = 20.0;
1.0.0
.See also:
textOffsetY:Float
Offsets the y position of the text by a certain number of pixels. This does not affect the measurement of the button. The button's height will not get smaller or larger when the text is offset from its default y position. Nor does it change the size of the text, so the text may appear outside of the button's bounds if the offset is large enough.
The following example offsets the y position of the button's text by 20 pixels:
button.textOffsetY = 20.0;
1.0.0
.See also:
verticalAlign:VerticalAlign
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.
1.0.0
.See also:
wordWrap:Bool
Determines if the text is displayed on a single line, or if it wraps.
In the following example, the button's text wraps at 150 pixels:
button.width = 150.0;
button.wordWrap = true;
1.0.0
.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):AbstractTextFormat
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:
setPadding(value:Float):Void
Sets all four padding properties to the same value.
1.0.0
.See also:
setTextFormatForState(state:ButtonState, textFormat:AbstractTextFormat):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: