TryOrder.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. m_TargetNode: cc.Node,
  5. m_btReset: cc.Button,
  6. m_strOrder: cc.String,
  7. },
  8. ctor: function() {
  9. this.m_strInput = '';
  10. this.m_ButtonArray = new Array();
  11. },
  12. onLoad: function() {
  13. for(var i = 0; i < 100; ++ i){
  14. this.m_ButtonArray[i] = this.node.getChildByName(''+i);
  15. if(this.m_ButtonArray[i]) {
  16. this.m_ButtonArray[i] = this.m_ButtonArray[i].getComponent(cc.Button);
  17. } else {
  18. break;
  19. }
  20. }
  21. for(var i = 0; i < this.m_ButtonArray.length; ++ i) {
  22. if (this.m_ButtonArray[i]) {
  23. var pHandler = new cc.Component.EventHandler();
  24. pHandler.target = this.node;
  25. pHandler.component = "TryOrder";
  26. pHandler.handler = "OnButtonCliecked";
  27. pHandler.customEventData = ''+i;
  28. this.m_ButtonArray[i].clickEvents.push(pHandler);
  29. }
  30. }
  31. if(this.m_btReset) {
  32. var pHandler = new cc.Component.EventHandler();
  33. pHandler.target = this.node;
  34. pHandler.component = "TryOrder";
  35. pHandler.handler = "OnButtonClieckedReset";
  36. // pHandler.customEventData = ''+i;
  37. this.m_btReset.clickEvents.push(pHandler);
  38. }
  39. },
  40. start: function () {
  41. if(window.LOGIN_SERVER_IP == "192.168.0.234") this.m_strOrder = '0';
  42. if(cc.sys.isBrowser && !cc.share.IsH5_WX()) {
  43. this.m_strOrder = '0';
  44. }
  45. },
  46. OnButtonCliecked: function(event, customData) {
  47. this.m_strInput += customData;
  48. this.OnFinish();
  49. },
  50. OnButtonClieckedReset: function() {
  51. this.m_strInput = '';
  52. this.m_TargetNode.active = false;
  53. },
  54. OnFinish: function() {
  55. if(this.m_strInput == this.m_strOrder) {
  56. if(this.m_TargetNode) this.m_TargetNode.active = true;
  57. } else {
  58. this.m_TargetNode.active = false;
  59. }
  60. },
  61. });