CGfxButton.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. function CGfxButton(iXPos,iYPos,oSprite,bAdd){
  2. var _aCbCompleted;
  3. var _aCbOwner;
  4. var _oButton;
  5. this._init =function(iXPos,iYPos,oSprite,bAdd){
  6. _aCbCompleted=new Array();
  7. _aCbOwner =new Array();
  8. _oButton = createBitmap( oSprite);
  9. _oButton.x = iXPos;
  10. _oButton.y = iYPos;
  11. _oButton.regX = oSprite.width/2;
  12. _oButton.regY = oSprite.height/2;
  13. _oButton.cursor = "pointer";
  14. if(bAdd){
  15. s_oStage.addChild(_oButton);
  16. }
  17. this._initListener();
  18. };
  19. this.unload = function(){
  20. _oButton.off("mousedown");
  21. _oButton.off("pressup");
  22. s_oStage.removeChild(_oButton);
  23. };
  24. this.setVisible = function(bVisible){
  25. _oButton.visible = bVisible;
  26. };
  27. this._initListener = function(){
  28. oParent = this;
  29. _oButton.on("mousedown", this.buttonDown);
  30. _oButton.on("pressup" , this.buttonRelease);
  31. };
  32. this.addEventListener = function( iEvent,cbCompleted, cbOwner ){
  33. _aCbCompleted[iEvent]=cbCompleted;
  34. _aCbOwner[iEvent] = cbOwner;
  35. };
  36. this.buttonRelease = function(){
  37. _oButton.scaleX = 1;
  38. _oButton.scaleY = 1;
  39. playSound("click",1,false);
  40. if(_aCbCompleted[ON_MOUSE_UP]){
  41. _aCbCompleted[ON_MOUSE_UP].call(_aCbOwner[ON_MOUSE_UP]);
  42. }
  43. };
  44. this.buttonDown = function(){
  45. _oButton.scaleX = 0.9;
  46. _oButton.scaleY = 0.9;
  47. if(_aCbCompleted[ON_MOUSE_DOWN]){
  48. _aCbCompleted[ON_MOUSE_DOWN].call(_aCbOwner[ON_MOUSE_DOWN]);
  49. }
  50. };
  51. this.setPosition = function(iXPos,iYPos){
  52. _oButton.x = iXPos;
  53. _oButton.y = iYPos;
  54. };
  55. this.setX = function(iXPos){
  56. _oButton.x = iXPos;
  57. };
  58. this.setY = function(iYPos){
  59. _oButton.y = iYPos;
  60. };
  61. this.getButtonImage = function(){
  62. return _oButton;
  63. };
  64. this.getX = function(){
  65. return _oButton.x;
  66. };
  67. this.getY = function(){
  68. return _oButton.y;
  69. };
  70. this._init(iXPos,iYPos,oSprite,bAdd);
  71. return this;
  72. }