| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- function CNumToggle(iXPos, iYPos, iNum, oParentContainer) {
- var _bActive;
- var _bBlock;
- var _aCbCompleted;
- var _aCbOwner;
- var _oButton;
- var _oButtonBg;
- var _oExtracted;
- var _aParams = [];
- this._init = function (iXPos, iYPos, iNum, oParentContainer) {
- _bBlock = false;
- _aCbCompleted = new Array();
- _aCbOwner = new Array();
- _oButton = new createjs.Container();
- _oButton.x = iXPos;
- _oButton.y = iYPos;
- oParentContainer.addChild(_oButton);
- var oSprite = s_oSpriteLibrary.getSprite('num_button');
- var oData = {
- images: [oSprite],
- framerate: 5,
- // 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 = false;
- _oButtonBg = createSprite(oSpriteSheet, "state_" + _bActive, (oSprite.width / 2) / 2, oSprite.height / 2, oSprite.width / 2, oSprite.height);
- _oButtonBg.stop();
- var oSprite = s_oSpriteLibrary.getSprite('ball');
- var oData = {
- images: [oSprite],
- // width, height & registration point of each sprite
- frames: {width: oSprite.width / NUM_DIFFERENT_BALLS, height: oSprite.height, regX: (oSprite.width / NUM_DIFFERENT_BALLS) / 2, regY: oSprite.height / 2},
- animations: {red: [0], green: [1], cyan: [0], violet: [1], blue: [1]}
- };
- var oSpriteSheet = new createjs.SpriteSheet(oData);
- _oExtracted = createSprite(oSpriteSheet, "red", (oSprite.width / NUM_DIFFERENT_BALLS) / 2, oSprite.height / 2, oSprite.width / NUM_DIFFERENT_BALLS, oSprite.height);//new createBitmap(oSprite);
- _oExtracted.gotoAndStop(0);
- _oExtracted.visible = false;
- if (!s_bMobile){
- _oButton.cursor = "pointer";
- }
- _oButton.addChild(_oButtonBg, _oExtracted);
- this._initListener();
- };
- this.unload = function () {
- _oButton.off("mousedown", this.buttonDown);
- _oButton.off("pressup", this.buttonRelease);
- oParentContainer.removeChild(_oButton);
- };
- 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.setActive = function (bActive) {
- _bActive = bActive;
- _oButtonBg.gotoAndStop("state_" + _bActive);
- };
- this.buttonRelease = function () {
- if (_bBlock) {
- return;
- }
- playSound("click", 1, false);
- _bActive = !_bActive;
- _oButtonBg.gotoAndStop("state_" + _bActive);
- if (_aCbCompleted[ON_MOUSE_UP]) {
- _aCbCompleted[ON_MOUSE_UP].call(_aCbOwner[ON_MOUSE_UP], _aParams);
- }
- };
- this.buttonDown = function () {
- if (_bBlock) {
- return;
- }
- 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.getGlobalPosition = function () {
- return {x: _oButton.localToGlobal(0, 0).x, y: _oButton.localToGlobal(0, 0).y};
- };
- this.block = function (bVal) {
- _bBlock = bVal;
- };
- this.setExtracted = function (bVal, iColor) {
- _oExtracted.visible = bVal;
- _oExtracted.gotoAndStop(iColor);
- };
- this.highlight = function () {
- _oButtonBg.gotoAndPlay(0);
- };
- this.stopHighlight = function () {
- _oButtonBg.gotoAndStop(1);
- };
- this._init(iXPos, iYPos, iNum, oParentContainer);
- }
|