SVItem.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. num: cc.Label,
  29. des: cc.Label,
  30. group: cc.Node,
  31. icon: cc.Node,
  32. },
  33. // LIFE-CYCLE CALLBACKS:
  34. // onLoad () {},
  35. start() {
  36. },
  37. updateUI(data) {
  38. this.num.string = data.id;
  39. this.des.string = data.des;
  40. this.checks(data.id)
  41. utils.loadHttpSpriteFrame(data.img, this.icon.getComponent(cc.Sprite));
  42. },
  43. checks(id) {
  44. switch (id) {
  45. case 1:
  46. case 2:
  47. case 3:
  48. this.setAll(this.group,id-1,true)
  49. break;
  50. default:
  51. this.setAll(this.group,0,false)
  52. break;
  53. }
  54. },
  55. setAll(parent,index,b){
  56. if (parent.active == b) {
  57. return
  58. }
  59. parent.active = b
  60. for (var i = 0; i <parent.children.length ; i++) {
  61. parent.children[i].active = false
  62. }
  63. parent.children[index].active = b
  64. }
  65. // update (dt) {},
  66. });