diff --git a/cocos2d/core/components/CCButton.js b/cocos2d/core/components/CCButton.js index fe5028196f..cb0137f80e 100644 --- a/cocos2d/core/components/CCButton.js +++ b/cocos2d/core/components/CCButton.js @@ -314,9 +314,17 @@ var Button = cc.Class({ if (!this.target) { this.target = this.node; } + }, + onEnable: function () { if (!CC_EDITOR) { this._registerEvent(); + } else { + this.node.on('spriteframe-changed', function(event) { + if (this.transition === Transition.SPRITE) { + this.normalSprite = event.detail.spriteFrame; + } + }.bind(this)); } }, @@ -446,6 +454,18 @@ var Button = cc.Class({ onDisable: function() { this._hovered = false; this._pressed = false; + + if (!CC_EDITOR) { + this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this); + this.node.off(cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this); + this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this); + this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this); + + this.node.off(cc.Node.EventType.MOUSE_ENTER, this._onMouseMoveIn, this); + this.node.off(cc.Node.EventType.MOUSE_LEAVE, this._onMouseMoveOut, this); + } else { + this.node.off('spriteframe-changed'); + } }, _applyTransition: function (color, sprite) { diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js index a67c1a6667..7be4f437ae 100644 --- a/cocos2d/core/components/CCSprite.js +++ b/cocos2d/core/components/CCSprite.js @@ -161,9 +161,15 @@ var Sprite = cc.Class({ return this._spriteFrame; }, set: function (value, force) { + if (this._spriteFrame === value) { + return; + } var lastSprite = this._spriteFrame; this._spriteFrame = value; this._applySpriteFrame(lastSprite); + if (CC_EDITOR) { + this.node.emit('spriteframe-changed', this); + } }, type: cc.SpriteFrame, },