| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- function CToggle(iXPos,iYPos,oSprite,bActive,oParentContainer){
- var _bDisable;
- var _bActive;
- var _aCbCompleted;
- var _aCbOwner;
- var _oButton;
- var _oParentContainer;
-
- this._init = function(iXPos,iYPos,oSprite,bActive){
- _aCbCompleted=new Array();
- _aCbOwner =new Array();
-
- var oData = {
- images: [oSprite],
- // width, height & registration point of each sprite
- frames: {width: oSprite.width/2, height: oSprite.height, regX: (oSprite.width/2)/2, regY: oSprite.height/2},
- animations: {state_true:[0],state_false:[1]}
- };
-
- var oSpriteSheet = new createjs.SpriteSheet(oData);
-
- _bActive = bActive;
- _bDisable = false;
- _oButton = createSprite(oSpriteSheet, "state_"+_bActive,(oSprite.width/2)/2,oSprite.height/2,oSprite.width/2,oSprite.height);
-
- _oButton.x = iXPos;
- _oButton.y = iYPos;
- _oButton.stop();
-
- _oParentContainer.addChild(_oButton);
-
- this._initListener();
- };
-
- this.unload = function(){
- _oButton.off("mousedown", this.buttonDown);
- _oButton.off("pressup" , this.buttonRelease);
-
- if(!s_bMobile){
- _oButton.off("mouseover", this.buttonOver);
- }
-
- _oParentContainer.removeChild(_oButton);
- };
-
- this._initListener = function(){
- _oButton.on("mousedown", this.buttonDown);
- _oButton.on("pressup" , this.buttonRelease);
-
- if(!s_bMobile){
- _oButton.on("mouseover", this.buttonOver);
- }
- };
-
- this.addEventListener = function( iEvent,cbCompleted, cbOwner ){
- _aCbCompleted[iEvent]=cbCompleted;
- _aCbOwner[iEvent] = cbOwner;
- };
-
- this.setActive = function(bActive){
- _bActive = bActive;
- _oButton.gotoAndStop("state_"+_bActive);
- };
-
- this.enable = function(){
- _bDisable = false;
- };
-
- this.disable = function(){
- _bDisable = true;
- };
-
- this.buttonRelease = function(){
- if(_bDisable){
- return
- };
-
- _oButton.scaleX = 1;
- _oButton.scaleY = 1;
-
- playSound("click",1,false);
-
- _bActive = !_bActive;
- _oButton.gotoAndStop("state_"+_bActive);
- if(_aCbCompleted[ON_MOUSE_UP]){
- _aCbCompleted[ON_MOUSE_UP].call(_aCbOwner[ON_MOUSE_UP],_bActive);
- }
- };
-
- 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]);
- }
- };
-
- this.buttonOver = function(evt){
- if(_bDisable){
- return
- };
-
- if(!s_bMobile){
- evt.target.cursor = "pointer";
- }
- };
-
- this.setPosition = function(iXPos,iYPos){
- _oButton.x = iXPos;
- _oButton.y = iYPos;
- };
-
- _oParentContainer = oParentContainer;
- this._init(iXPos,iYPos,oSprite,bActive);
- }
|