ButtonHelper Class
The ButtonHelper is a helper class to create interactive buttons from MovieClip or Sprite instances. This class will intercept mouse events from an object, and automatically call gotoAndStop or gotoAndPlay, to the respective animation labels, add a pointer cursor, and allows the user to define a hit state frame.
The ButtonHelper instance does not need to be added to the stage, but a reference should be maintained to prevent garbage collection.
Note that over states will not work unless you call enableMouseOver.
Example
var helper = new createjs.ButtonHelper(myInstance, "out", "over", "down", false, myInstance, "hit");
myInstance.addEventListener("click", handleClick);
function handleClick(event) {
// Click Happened.
}
Constructor
ButtonHelper
-
target
-
[outLabel="out"]
-
[overLabel="over"]
-
[downLabel="down"]
-
[play=false]
-
[hitArea]
-
[hitLabel]
Parameters:
-
target
Sprite | MovieClipThe instance to manage.
-
[outLabel="out"]
String optionalThe label or animation to go to when the user rolls out of the button.
-
[overLabel="over"]
String optionalThe label or animation to go to when the user rolls over the button.
-
[downLabel="down"]
String optionalThe label or animation to go to when the user presses the button.
-
[play=false]
Boolean optionalIf the helper should call "gotoAndPlay" or "gotoAndStop" on the button when changing states.
-
[hitArea]
DisplayObject optionalAn optional item to use as the hit state for the button. If this is not defined, then the button's visible states will be used instead. Note that the same instance as the "target" argument can be used for the hitState.
-
[hitLabel]
String optionalThe label or animation on the hitArea instance that defines the hitArea bounds. If this is null, then the default state of the hitArea will be used. *
Item Index
Methods
- _reset
- getEnabled
- getEnabled deprecated
- handleEvent
- setEnabled
- setEnabled deprecated
- toString
Methods
_reset
()
protected
Injected into target. Preserves the paused state through a reset.
Properties
downLabel
String | Number
The label name or frame number to display when the user presses on the target. Defaults to "down".
outLabel
String | Number
The label name or frame number to display when the user mouses over the target. Defaults to "out".
overLabel
String | Number
The label name or frame number to display when the user mouses out of the target. Defaults to "over".
play
Boolean
If true, then ButtonHelper will call gotoAndPlay, if false, it will use gotoAndStop. Default is false.
Default: false