CustomSwitch.js 808 B

123456789101112131415161718192021222324252627
  1. //customswitch.js
  2. cc.Class({
  3. extends: cc.BaseClass,
  4. properties: {
  5. NdClose:cc.Node,
  6. NdOpen:cc.Node,
  7. IsChecked:{
  8. default:true,
  9. tooltip: "switch statue",
  10. notify: function (oldValue) {
  11. if(this.NdOpen)this.NdOpen.active = !oldValue;
  12. if(this.NdClose)this.NdClose.active = oldValue;
  13. },
  14. },
  15. CheckEvents:[cc.Component.EventHandler],
  16. },
  17. start :function() {
  18. this.node.on(cc.Node.EventType.TOUCH_END,this._onTouchEnded,this);
  19. },
  20. _onTouchEnded:function(){
  21. this.IsChecked = !this.IsChecked;
  22. for(var i in this.CheckEvents){
  23. this.CheckEvents[i].emit([this, this.CheckEvents[i].customEventData]);
  24. }
  25. },
  26. });