Browse files

Binds mouse events for SimpleButton

  • Loading branch information...
1 parent 4185815 commit 4f0c1d9945178816773b7b9c35abea4037c2c9a0 @yurydelendik yurydelendik committed Oct 31, 2012
Showing with 29 additions and 1 deletion.
  1. +29 −1 src/flash/display/SimpleButton.js
View
30 src/flash/display/SimpleButton.js
@@ -38,10 +38,38 @@ const SimpleButtonDefinition = (function () {
this._downState = createSprite(s.states.down, this);
this._hitTestState = createSprite(s.states.hitTest, this);
}
+ this._isMouseDown = false;
+ this._isMouseOver = false;
+
+ // binding mouse events
+ const MouseEventClass = avm2.systemDomain.getClass("flash.events.MouseEvent");
+ this.addEventListener(MouseEventClass.MOUSE_DOWN, function (evt) {
+ this._isMouseDown = true;
+ this._updateButton();
+ }.bind(this), true);
+ this.addEventListener(MouseEventClass.MOUSE_UP, function (evt) {
+ this._isMouseDown = false;
+ this._updateButton();
+ }.bind(this), true);
+ this.addEventListener(MouseEventClass.MOUSE_OVER, function (evt) {
+ this._isMouseOver = true;
+ this._updateButton();
+ }.bind(this), true);
+ this.addEventListener(MouseEventClass.MOUSE_OUT, function (evt) {
+ this._isMouseOver = false;
+ this._updateButton();
+ }.bind(this), true);
+
},
_updateButton: function () {
- this._children = [this.upState];
+ var state = this.upState;
+ if (this._isMouseDown && this._isMouseOver && this.downState) {
+ state = this.downState;
+ } else if (this._isMouseOver && this.overState) {
+ state = this.overState;
+ }
+ this._children = [state];
}
};

0 comments on commit 4f0c1d9

Please sign in to comment.