Button (CreateJS) Class
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 CreateJS 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.
Constructor
Button (CreateJS)
-
[imageSettings]
-
[label=null]
-
[enabled=true]
Parameters:
-
[imageSettings]
Object | Image | HTMLCanvasElement optionalInformation 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 optionalThe image to use for all of the button states.
-
[priority=null]
Array optionalThe 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 optionalThe visual information about the up state.
-
[src]
createjs.Rectangle optionalThe sourceRect for the state within the image. -
[trim=null]
createjs.Rectangle optionalTrim data about the state, where x & y are how many pixels were trimmed off the left and right, and height & width are the untrimmed size of the button. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" from the label parameter may be overridden.
-
-
[over=null]
Object optionalThe visual information about the over state. If omitted, uses the up state.
-
[src]
createjs.Rectangle optionalThe sourceRect for the state within the image. -
[trim=null]
createjs.Rectangle optionalTrim data about the state, where x & y are how many pixels were trimmed off the left and right, and height & width are the untrimmed size of the button. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" from the label parameter may be overridden.
-
-
[down=null]
Object optionalThe visual information about the down state. If omitted, uses the up state.
-
[src]
createjs.Rectangle optionalThe sourceRect for the state within the image. -
[trim=null]
createjs.Rectangle optionalTrim data about the state, where x & y are how many pixels were trimmed off the left and right, and height & width are the untrimmed size of the button. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" from the label parameter may be overridden.
-
-
[disabled=null]
Object optionalThe visual information about the disabled state. If omitted, uses the up state.
-
[src]
createjs.Rectangle optionalThe sourceRect for the state within the image. -
[trim=null]
createjs.Rectangle optionalTrim data about the state, where x & y are how many pixels were trimmed off the left and right, and height & width are the untrimmed size of the button. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" from the label parameter may be overridden.
-
-
[<yourCustomState>=null]
Object optionalThe 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 optionalThe sourceRect for the state within the image. -
[trim=null]
createjs.Rectangle optionalTrim data about the state, where x & y are how many pixels were trimmed off the left and right, and height & width are the untrimmed size of the button. -
[label=null]
Object optionalLabel information specific to this state. Properties on this parameter override data in the label parameter for this button state only. All values except "text" from the label parameter may be overridden.
-
-
[origin=null]
createjs.Point optionalAn 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 optionalInformation about the text label on the button. Omitting this makes the button not use a label.
-
[text]
String optionalThe text to display on the label.
-
[font]
String optionalThe font name and size to use on the label, as createjs.Text expects.
-
[color]
String optionalThe color of the text to use on the label, as createjs.Text expects.
-
[textBaseline="middle"]
String optionalThe baseline for the label text, as createjs.Text expects.
-
[stroke=null]
Object optionalThe stroke to use for the label text, if desired, as createjs.Text (CloudKid fork only) expects.
-
[shadow=null]
createjs.Shadow optionalA shadow object to apply to the label text.
-
[x="center"]
String | Number optionalAn 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 optionalA 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 optionalWhether or not the button is initially enabled.
Item Index
Methods
Properties
Methods
_addProperty
-
propertyName
Adds a property to the button. Setting the property sets the value in _stateFlags and calls _updateState().
Parameters:
-
propertyName
StringThe property name to add to the button.
_onClick
()
private
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.
_onMouseDown
()
private
The callback for when the button receives a mouse down event.
_onMouseOut
()
private
The callback for when the mouse leaves the button area.
_onMouseOver
()
private
The callback for when the button is moused over.
_onMouseUp
()
private
The callback for when the button for when the mouse/touch is released on the button
- only when the button was held down initially.
_updateState
()
private
Updates back based on the current button state.
destroy
()
public
Destroys the button.
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.
Parameters:
-
image
Image | HTMLCanvasElementThe image to use for all of the button states, in the standard up/over/down format.
-
[disabledSettings]
Object optionalThe settings object for the disabled state. If omitted, no disabled state is created.
-
[saturation]
Number optionalThe saturation adjustment for the disabled state. 100 is fully saturated, 0 is unchanged, -100 is desaturated.
-
[brightness]
Number optionalThe brightness adjustment for the disabled state. 100 is fully bright, 0 is unchanged, -100 is completely dark.
-
[contrast]
Number optionalThe contrast adjustment for the disabled state. 100 is full contrast, 0 is unchanged, -100 is no contrast.
-
-
[highlightSettings]
Object optionalThe settings object for the highlight state. If omitted, no state is created.
-
[size]
Number optionalHow many pixels to make the glow, eg 8 for an 8 pixel increase on each side.
-
[red]
Number optionalThe red value for the glow, from 0 to 255.
-
[green]
Number optionalThe green value for the glow, from 0 to 255.
-
[blue]
Number optionalThe blue value for the glow, from 0 to 255.
-
[alpha]
Number optionalThe alpha value for the glow, from 0 to 255, with 0 being transparent and 255 fully opaque.
-
initialize
-
[imageSettings]
-
[label=null]
-
[enabled=true]
Constructor for the button when using CreateJS.
Parameters:
-
[imageSettings]
Object | Image | HTMLCanvasElement optionalSee the constructor for more information
-
[label=null]
Object optionalInformation about the text label on the button. Omitting this makes the button not use a label.
-
[enabled=true]
Boolean optionalWhether or not the button is initially enabled.
setText
-
text
Sets the text of the label. This does nothing if the button was not initialized with a label.
Parameters:
-
text
StringThe text to set the label to.
Properties
_height
Number
private
The height of the button art, independent of the scaling of the button itself.
_offset
createjs.Point
private
An offset to button positioning, generally used to adjust for a highlight around the button.
_stateData
Object
private
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
Array
private
An array of state names (Strings), in their order of priority. The standard order previously was ["highlighted", "disabled", "down", "over", "selected", "up"].
back
createjs.Bitmap
public
The sprite that is the body of the button. The type of this property is dependent on which version of the OS library is used.
height
Number
The height of the button, based on the height of back. This value is affected by scale.
label
createjs.Text
public
The text field of the button. The label is centered by both width and height on the button. The type of this property is dependent on which version of the OS library is used.