A Multipurpose button class. It is designed to have one image, and an optional text label. The button can be a normal button or a selectable button. The button functions similarly with both EaselJS and PIXI, but slightly differently in initialization and callbacks. Add event listeners for click and mouseover to know about button clicks and mouse overs, respectively.
springroll.easeljs.Button
[imageSettings]
[label=null]
[enabled=true]
[imageSettings]
Object | Image | HTMLCanvasElement
optional
Information about the art to be used for button states, as well as if the button is selectable or not. If this is an Image or Canvas element, then the button assumes that the image is full width and 3 images tall, in the order (top to bottom) up, over, down. If so, then the properties of imageSettings are ignored.
[image]
Image | HTMLCanvasElement
optional
The image to use for all of the button states.
[priority=null]
Array
optional
The state priority order. If omitted, defaults to
["disabled", "down", "over",
"up"]
. Previous versions of Button
used a hard coded order:
["highlighted", "disabled", "down",
"over", "selected", "up"]
.
[up]
Object
optional
The visual information about the up state.
[src]
createjs.Rectangle
optional
[trim=null]
createjs.Rectangle
optional
[label=null]
Object
optional
[over=null]
Object
optional
The visual information about the over state. If omitted, uses the up state.
[src]
createjs.Rectangle
optional
[trim=null]
createjs.Rectangle
optional
[label=null]
Object
optional
[down=null]
Object
optional
The visual information about the down state. If omitted, uses the up state.
[src]
createjs.Rectangle
optional
[trim=null]
createjs.Rectangle
optional
[label=null]
Object
optional
[disabled=null]
Object
optional
The visual information about the disabled state. If omitted, uses the up state.
[src]
createjs.Rectangle
optional
[trim=null]
createjs.Rectangle
optional
[label=null]
Object
optional
[<yourCustomState>=null]
Object
optional
The visual information about a custom state found in imageSettings.priority. Any state added this way has a property of the same name added to the button. Examples of previous states that have been moved to this system are "selected" and "highlighted".
[src]
createjs.Rectangle
optional
[trim=null]
createjs.Rectangle
optional
[label=null]
Object
optional
[origin=null]
createjs.Point
optional
An optional offset for all button graphics, in case you want button positioning to not include a highlight glow, or any other reason you would want to offset the button art and label.
[label=null]
Object
optional
Information about the text label on the button. Omitting this makes the button not use a label.
[text]
String
optional
The text to display on the label.
[font]
String
optional
The font name and size to use on the label, as createjs.Text expects.
[color]
String
optional
The color of the text to use on the label, as createjs.Text expects.
[textBaseline="middle"]
String
optional
The baseline for the label text, as createjs.Text expects.
[stroke=null]
Object
optional
The stroke to use for the label text, if desired, as createjs.Text (springroll fork only) expects.
[shadow=null]
createjs.Shadow
optional
A shadow object to apply to the label text.
[x="center"]
String | Number
optional
An x position to place the label text at relative to the button. If omitted, "center" is used, which attempts to horizontally center the label on the button.
[y="center"]
String | Number
optional
A y position to place the label text at relative to the button. If omitted, "center" is used, which attempts to vertically center the label on the button. This may be unreliable - see documentation for createjs.Text.getMeasuredLineHeight().
[enabled=true]
Boolean
optional
Whether or not the button is initially enabled.
_addProperty
propertyName
Adds a property to the button. Setting the property sets the value in _stateFlags and calls _updateState().
propertyName
String
The property name to add to the button.
_onClick
The callback for when the button the button is clicked or tapped on. This is the most reliable way of detecting mouse up/touch end events that are on this button while letting the pressup event handle the mouse up/touch ends on and outside the button.
_onMouseUp
The callback for when the button for when the mouse/touch is released on the button
_updateState
Updates back based on the current button state.
The state data for the active button state, so that subclasses can use the value picked by this function without needing to calculate it themselves.
cacheByBounds
[buffer=0]
[scale=1]
Does a cache by the nominalBounds set from Flash
[buffer=0]
Int
optional
The space around the nominal bounds to include in cache image
[scale=1]
Number
optional
The scale to cache the container by.
cacheByRect
rect
[buffer=0]
[scale=1]
Does a cache by a given rectangle
rect
createjs.Rectangle
The rectangle to cache with.
[buffer=0]
Int
optional
Additional space around the rectangle to include in cache image
[scale=1]
Number
optional
The scale to cache the container by.
generateDefaultStates
image
[disabledSettings]
[highlightSettings]
Generates a desaturated up state as a disabled state, and an update with a solid colored glow for a highlighted state.
image
Image | HTMLCanvasElement
The image to use for all of the button states, in the standard up/over/down format.
[disabledSettings]
Object
optional
The settings object for the disabled state. If omitted, no disabled state is created.
[saturation]
Number
optional
The saturation adjustment for the disabled state. 100 is fully saturated, 0 is unchanged, -100 is desaturated.
[brightness]
Number
optional
The brightness adjustment for the disabled state. 100 is fully bright, 0 is unchanged, -100 is completely dark.
[contrast]
Number
optional
The contrast adjustment for the disabled state. 100 is full contrast, 0 is unchanged, -100 is no contrast.
[highlightSettings]
Object
optional
The settings object for the highlight state. If omitted, no state is created.
[size]
Number
optional
How many pixels to make the glow, eg 8 for an 8 pixel increase on each side.
[red]
Number
optional
The red value for the glow, from 0 to 255.
[green]
Number
optional
The green value for the glow, from 0 to 255.
[blue]
Number
optional
The blue value for the glow, from 0 to 255.
[alpha=255]
Number
optional
The alpha value for the glow, from 0 to 255, with 0 being transparent and 255 fully opaque.
[rgba]
Array
optional
An array of values to use for red, green, blue, and optionally alpha that can be used instead of providing separate properties on highlightSettings.
An object for use as the 'imageSettings' parameter on a new Button.
generateSettingsFromAtlas
atlas
baseName
statePriority
Generates an 'imageSettings' from a TextureAtlas, a base name for all frames, and a list of state priorities.
atlas
springroll.easeljs.TextureAtlas
The TextureAtlas to pull all frames from.
baseName
String
The base name for all frames in the atlas.
statePriority
Array
The state order, as well as determining frame names in the
atlas. Each state frame name in the atlas should be
baseName + "_" + statePriority[i]
.
setText
text
Sets the text of the label. This does nothing if the button was not initialized with a label.
text
String
The text to set the label to.
_height
The height of the button art, independent of the scaling of the button itself.
_offset
An offset to button positioning, generally used to adjust for a highlight around the button.
_stateData
A dictionary of state graphic data, keyed by state name. Each object contains the sourceRect (src) and optionally 'trim', another Rectangle. Additionally, each object will contain a 'label' object if the button has a text label.
_statePriority
An array of state names (Strings), in their order of priority. The standard order previously was ["highlighted", "disabled", "down", "over", "selected", "up"].
height
The height of the button, based on the height of back. This value is affected by scale.