function CLevelBut(iXPos, iYPos, oSprite, bActive, Level) { var _bActive; var _aCbCompleted; var _aCbOwner; var _aButton = new Array(); var _aParams = []; var _oButton; 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; _oButton = createSprite(oSpriteSheet, "state_" + _bActive, (oSprite.width / 2) / 2, oSprite.height / 2, oSprite.width / 2, oSprite.height); _oButton.mouseEnabled = bActive; _oButton.x = iXPos; _oButton.y = iYPos; _oButton.stop(); if (!s_bMobile){ _oButton.cursor = "pointer"; } s_oStage.addChild(_oButton); _aButton.push(_oButton); var oLevelText; oLevelText = new createjs.Text(Level, "50px " + PRIMARY_FONT, "#ffff00"); oLevelText.x = iXPos; oLevelText.y = iYPos + 15; oLevelText.textAlign = "center"; oLevelText.textBaseline = "alphabetic"; oLevelText.lineWidth = 200; s_oStage.addChild(oLevelText); this._initListener(); }; this.unload = function () { _oButton.off("mousedown", this.buttonDown); _oButton.off("pressup", this.buttonRelease); s_oStage.removeChild(_oButton); }; this._initListener = function () { _oButton.on("mousedown", this.buttonDown); _oButton.on("pressup", this.buttonRelease); }; this.viewBut = function (oButton) { s_oStage.addChild(oButton); }; 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.ifClickable = function () { if (_oButton.mouseEnabled === true) { return 1; } return 0; }; this.setActive = function (iLevel, bActive) { _bActive = bActive; _aButton[iLevel].gotoAndStop("state_" + _bActive); _aButton[iLevel].mouseEnabled = true; }; this.buttonRelease = function () { _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], _aParams); } }; this.buttonDown = function () { _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.setVisible = function (bVisible) { _oButton.visible = bVisible; }; this._init(iXPos, iYPos, oSprite, bActive); }