| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- function CGfxButton(iXPos,iYPos,oSprite,oParentContainer){
-
- var _iScale;
-
- var _oParentContainer = oParentContainer;
-
- var _aCbCompleted;
- var _aCbOwner;
- var _aParams = [];
- var _oButton;
-
- var _oTween = null;
- var _oParent = this;
-
- this._init =function(iXPos,iYPos,oSprite){
- _iScale = 1;
-
- _aCbCompleted=new Array();
- _aCbOwner =new Array();
-
- _oButton = createBitmap( oSprite);
- _oButton.x = iXPos;
- _oButton.y = iYPos;
-
- _oButton.regX = oSprite.width/2;
- _oButton.regY = oSprite.height/2;
- _oButton.cursor = "pointer";
-
- if(!_oParentContainer){
- _oParentContainer = s_oStage;
- }
-
- _oParentContainer.addChild(_oButton);
-
- this._initListener();
- };
-
- this.unload = function(){
- _oButton.off("mousedown", this.buttonDown);
- _oButton.off("pressup" , this.buttonRelease);
-
- if(_oTween){
- createjs.Tween.removeTweens(_oTween);
- }
- _oParentContainer.removeChild(_oButton);
- };
-
- this.setVisible = function(bVisible){
- _oButton.visible = bVisible;
- };
-
- this._initListener = function(){
- _oButton.on("mousedown", this.buttonDown);
- _oButton.on("pressup" , this.buttonRelease);
- };
-
- this.addEventListener = function( iEvent,cbCompleted, cbOwner ){
- _aCbCompleted[iEvent]=cbCompleted;
- _aCbOwner[iEvent] = cbOwner;
- };
-
- this.addEventListenerWithParams = function(iEvent,cbCompleted, cbOwner,aParams){
- _aCbCompleted[iEvent]=cbCompleted;
- _aCbOwner[iEvent] = cbOwner;
- _aParams = aParams;
- };
-
- this.buttonRelease = function(){
- _oButton.scaleX = _iScale;
- _oButton.scaleY = _iScale;
-
- playSound("click",1,false);
-
- if(_aCbCompleted[ON_MOUSE_UP]){
- _aCbCompleted[ON_MOUSE_UP].call(_aCbOwner[ON_MOUSE_UP],_aParams);
- }
- };
-
- this.buttonDown = function(){
- _oButton.scaleX = _iScale*0.9;
- _oButton.scaleY = _iScale*0.9;
-
-
-
- if(_aCbCompleted[ON_MOUSE_DOWN]){
- _aCbCompleted[ON_MOUSE_DOWN].call(_aCbOwner[ON_MOUSE_DOWN],_aParams);
- }
- };
-
- this.setScale = function(iValue){
- _iScale = iValue;
- _oButton.scaleX = iValue;
- _oButton.scaleY = iValue;
- };
-
- this.setPosition = function(iXPos,iYPos){
- _oButton.x = iXPos;
- _oButton.y = iYPos;
- };
-
- this.moveInPosition = function(iXPos,iYPos){
- createjs.Tween.get(_oButton).to({x: iXPos, y: iYPos},1000, createjs.Ease.quadOut).call(function(){});
- };
-
- this.setX = function(iXPos){
- _oButton.x = iXPos;
- };
-
- this.setY = function(iYPos){
- _oButton.y = iYPos;
- };
-
- this.getButtonImage = function(){
- return _oButton;
- };
-
- this.pulseAnimation = function(){
- _oTween = createjs.Tween.get(_oButton).to({scaleX: _iScale*0.9, scaleY: _iScale*0.9},850, createjs.Ease.quadOut).to({scaleX: _iScale, scaleY: _iScale},650, createjs.Ease.quadIn).call(function(){
- _oParent.pulseAnimation();
- });
- };
-
- this.trebleAnimation = function(){
- _oTween = createjs.Tween.get(_oButton).to({rotation: 5},75, createjs.Ease.quadOut).to({rotation: -5},140, createjs.Ease.quadIn).to({rotation: 0},75, createjs.Ease.quadIn).wait(750).call(function(){
- _oParent.trebleAnimation();
- });
- };
-
- this.getX = function(){
- return _oButton.x;
- };
-
- this.getY = function(){
- return _oButton.y;
- };
- this._init(iXPos,iYPos,oSprite);
-
- return this;
- }
|