| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- function CGfxButton(iXPos,iYPos,oSprite){
- var _bDisable;
- var _iWidth;
- var _iHeight;
- var _aCbCompleted;
- var _aCbOwner;
- var _aParams = [];
- var _oButton;
-
- this._init =function(iXPos,iYPos,oSprite){
- _bDisable = false;
- _aCbCompleted=new Array();
- _aCbOwner =new Array();
-
- _iWidth = oSprite.width;
- _iHeight = oSprite.height;
-
- _oButton = createBitmap( oSprite);
- _oButton.x = iXPos;
- _oButton.y = iYPos;
-
- _oButton.regX = oSprite.width/2;
- _oButton.regY = oSprite.height/2;
- _oButton.cursor = "pointer";
- s_oStage.addChild(_oButton);
-
-
- this._initListener();
- };
-
- this.unload = function(){
- _oButton.off("mousedown", this.buttonDown);
- _oButton.off("pressup" , this.buttonRelease);
-
- s_oStage.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(){
- if(_bDisable){
- return;
- }
-
- playSound("click", 1, false);
-
- _oButton.scaleX = 1;
- _oButton.scaleY = 1;
- if(_aCbCompleted[ON_MOUSE_UP]){
- _aCbCompleted[ON_MOUSE_UP].call(_aCbOwner[ON_MOUSE_UP],_aParams);
- }
- };
-
- this.buttonDown = function(){
- if(_bDisable){
- return;
- }
- _oButton.scaleX = 0.9;
- _oButton.scaleY = 0.9;
- if(_aCbCompleted[ON_MOUSE_DOWN]){
- _aCbCompleted[ON_MOUSE_DOWN].call(_aCbOwner[ON_MOUSE_DOWN],_aParams);
- }
- };
-
- this.setPosition = function(iXPos,iYPos){
- _oButton.x = iXPos;
- _oButton.y = iYPos;
- };
-
- this.setX = function(iXPos){
- _oButton.x = iXPos;
- };
-
- this.setY = function(iYPos){
- _oButton.y = iYPos;
- };
- this.enable = function(){
- _bDisable = false;
-
- _oButton.filters = [];
- _oButton.cache(0,0,_iWidth,_iHeight);
- };
-
- this.disable = function(){
- _bDisable = true;
-
- var matrix = new createjs.ColorMatrix().adjustSaturation(-100).adjustBrightness(40);
- _oButton.filters = [
- new createjs.ColorMatrixFilter(matrix)
- ];
- _oButton.cache(0,0,_iWidth,_iHeight);
- };
-
- this.getButtonImage = function(){
- return _oButton;
- };
-
-
- this.getX = function(){
- return _oButton.x;
- };
-
- this.getY = function(){
- return _oButton.y;
- };
- this._init(iXPos,iYPos,oSprite);
-
- return this;
- }
|