CHitArea.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. function CHitArea(iXPos,iYPos,oSprite){
  2. var _aCbCompleted;
  3. var _aCbOwner;
  4. var _oButton;
  5. this._init =function(iXPos,iYPos,oSprite){
  6. _aCbCompleted=new Array();
  7. _aCbOwner =new Array();
  8. _oButton = new createBitmap( oSprite);
  9. _oButton.x = iXPos;
  10. _oButton.y = iYPos;
  11. _oButton.regX = oSprite.width/2;
  12. _oButton.regY = oSprite.height/2;
  13. s_oStage.addChild(_oButton);
  14. this._initListener();
  15. };
  16. this.unload = function(){
  17. _oButton.off("mousedown", this.buttonDown);
  18. _oButton.off("pressup" , this.buttonRelease);
  19. _oButton.off("pressmove" , this.onPressMove);
  20. if(s_bMobile === false){
  21. _oButton.off("mouseover" , this.buttonOver);
  22. _oButton.off("mouseout" , this.buttonOut);
  23. }
  24. s_oStage.removeChild(_oButton);
  25. };
  26. this.setVisible = function(bVisible){
  27. _oButton.visible = bVisible;
  28. };
  29. this._initListener = function(){
  30. _oButton.on("mousedown", this.buttonDown);
  31. _oButton.on("pressup" , this.buttonRelease);
  32. _oButton.on("pressmove" , this.onPressMove);
  33. if(s_bMobile === false){
  34. _oButton.on("mouseover" , this.buttonOver);
  35. _oButton.on("mouseout" , this.buttonOut);
  36. }
  37. };
  38. this.addEventListener = function( iEvent,cbCompleted, cbOwner ){
  39. _aCbCompleted[iEvent]=cbCompleted;
  40. _aCbOwner[iEvent] = cbOwner;
  41. };
  42. this.buttonRelease = function(evt){
  43. _oButton.scaleX = 1;
  44. _oButton.scaleY = 1;
  45. if(_aCbCompleted[ON_MOUSE_UP]){
  46. _aCbCompleted[ON_MOUSE_UP].call(_aCbOwner[ON_MOUSE_UP],{event:evt});
  47. }
  48. };
  49. this.buttonDown = function(evt){
  50. _oButton.scaleX = 0.9;
  51. _oButton.scaleY = 0.9;
  52. if(_aCbCompleted[ON_MOUSE_DOWN]){
  53. _aCbCompleted[ON_MOUSE_DOWN].call(_aCbOwner[ON_MOUSE_DOWN],{event:evt});
  54. }
  55. };
  56. this.onPressMove = function(evt){
  57. if(_aCbCompleted[ON_PRESS_MOVE]){
  58. _aCbCompleted[ON_PRESS_MOVE].call(_aCbOwner[ON_PRESS_MOVE],{event:evt});
  59. }
  60. };
  61. this.buttonOver = function(){
  62. if(_aCbCompleted[ON_MOUSE_OVER]){
  63. _aCbCompleted[ON_MOUSE_OVER].call(_aCbOwner[ON_MOUSE_OVER]);
  64. }
  65. };
  66. this.buttonOut = function(){
  67. if(_aCbCompleted[ON_MOUSE_OUT]){
  68. _aCbCompleted[ON_MOUSE_OUT].call(_aCbOwner[ON_MOUSE_OUT]);
  69. }
  70. };
  71. this.setPosition = function(iXPos,iYPos){
  72. _oButton.x = iXPos;
  73. _oButton.y = iYPos;
  74. };
  75. this.setX = function(iXPos){
  76. _oButton.x = iXPos;
  77. };
  78. this.setY = function(iYPos){
  79. _oButton.y = iYPos;
  80. };
  81. this.getSprite = function(){
  82. return _oButton;
  83. };
  84. this.getX = function(){
  85. return _oButton.x;
  86. };
  87. this.getY = function(){
  88. return _oButton.y;
  89. };
  90. this._init(iXPos,iYPos,oSprite);
  91. return this;
  92. }