1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  3 
  4  http://www.cocos2d-x.org
  5 
  6  Permission is hereby granted, free of charge, to any person obtaining a copy
  7  of this software and associated documentation files (the "Software"), to deal
  8  in the Software without restriction, including without limitation the rights
  9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10  copies of the Software, and to permit persons to whom the Software is
 11  furnished to do so, subject to the following conditions:
 12 
 13  The above copyright notice and this permission notice shall be included in
 14  all copies or substantial portions of the Software.
 15 
 16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22  THE SOFTWARE.
 23  ****************************************************************************/
 24 
 25 /**
 26  * Base class for ccui.CheckBox
 27  * @class
 28  * @extends ccui.Widget
 29  *
 30  * @property {Boolean}  selected    - Indicate whether the check box has been selected
 31  */
 32 ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{
 33     _backGroundBoxRenderer: null,
 34     _backGroundSelectedBoxRenderer: null,
 35     _frontCrossRenderer: null,
 36     _backGroundBoxDisabledRenderer: null,
 37     _frontCrossDisabledRenderer: null,
 38     _isSelected: true,
 39     _checkBoxEventListener: null,
 40     _checkBoxEventSelector: null,
 41     _backGroundTexType: null,
 42     _backGroundSelectedTexType: null,
 43     _frontCrossTexType: null,
 44     _backGroundDisabledTexType: null,
 45     _frontCrossDisabledTexType: null,
 46     _backGroundFileName: "",
 47     _backGroundSelectedFileName: "",
 48     _frontCrossFileName: "",
 49     _backGroundDisabledFileName: "",
 50     _frontCrossDisabledFileName: "",
 51     _className:"CheckBox",
 52     ctor: function () {
 53         ccui.Widget.prototype.ctor.call(this);
 54         this._backGroundBoxRenderer = null;
 55         this._backGroundSelectedBoxRenderer = null;
 56         this._frontCrossRenderer = null;
 57         this._backGroundBoxDisabledRenderer = null;
 58         this._frontCrossDisabledRenderer = null;
 59         this._isSelected = true;
 60         this._checkBoxEventListener = null;
 61         this._checkBoxEventSelector = null;
 62         this._backGroundTexType = ccui.Widget.LOCAL_TEXTURE;
 63         this._backGroundSelectedTexType = ccui.Widget.LOCAL_TEXTURE;
 64         this._frontCrossTexType = ccui.Widget.LOCAL_TEXTURE;
 65         this._backGroundDisabledTexType = ccui.Widget.LOCAL_TEXTURE;
 66         this._frontCrossDisabledTexType = ccui.Widget.LOCAL_TEXTURE;
 67         this._backGroundFileName = "";
 68         this._backGroundSelectedFileName = "";
 69         this._frontCrossFileName = "";
 70         this._backGroundDisabledFileName = "";
 71         this._frontCrossDisabledFileName = "";
 72     },
 73     init: function () {
 74         if (ccui.Widget.prototype.init.call(this)) {
 75             this.setTouchEnabled(true);
 76             this.setSelectedState(false);
 77             return true;
 78         }
 79         return false;
 80     },
 81 
 82     initRenderer: function () {
 83         this._backGroundBoxRenderer = cc.Sprite.create();
 84         this._backGroundSelectedBoxRenderer = cc.Sprite.create();
 85         this._frontCrossRenderer = cc.Sprite.create();
 86         this._backGroundBoxDisabledRenderer = cc.Sprite.create();
 87         this._frontCrossDisabledRenderer = cc.Sprite.create();
 88         cc.Node.prototype.addChild.call(this, this._backGroundBoxRenderer, ccui.CheckBox.BOX_RENDERER_ZORDER, -1);
 89         cc.Node.prototype.addChild.call(this, this._backGroundSelectedBoxRenderer, ccui.CheckBox.BOX_SELECTED_RENDERER_ZORDER, -1);
 90         cc.Node.prototype.addChild.call(this, this._frontCrossRenderer, ccui.CheckBox.FRONT_CROSS_RENDERER_ZORDER, -1);
 91         cc.Node.prototype.addChild.call(this, this._backGroundBoxDisabledRenderer, ccui.CheckBox.BOX_DISABLED_RENDERER_ZORDER, -1);
 92         cc.Node.prototype.addChild.call(this, this._frontCrossDisabledRenderer, ccui.CheckBox.FRONT_CROSS_DISABLED_RENDERER_ZORDER, -1);
 93     },
 94 
 95     /**
 96      * Load textures for checkbox.
 97      * @param {String} backGround
 98      * @param {String} backGroundSelected
 99      * @param {String} cross
100      * @param {String} backGroundDisabled
101      * @param {String} frontCrossDisabled
102      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
103      */
104     loadTextures: function (backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType) {
105         this.loadTextureBackGround(backGround, texType);
106         this.loadTextureBackGroundSelected(backGroundSelected, texType);
107         this.loadTextureFrontCross(cross, texType);
108         this.loadTextureBackGroundDisabled(backGroundDisabled, texType);
109         this.loadTextureFrontCrossDisabled(frontCrossDisabled, texType);
110     },
111 
112     /**
113      * Load backGround texture for checkbox.
114      * @param {String} backGround
115      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
116      */
117     loadTextureBackGround: function (backGround, texType) {
118         if (!backGround) {
119             return;
120         }
121         texType = texType || ccui.Widget.LOCAL_TEXTURE;
122         this._backGroundFileName = backGround;
123         this._backGroundTexType = texType;
124         var bgBoxRenderer = this._backGroundBoxRenderer;
125         switch (this._backGroundTexType) {
126             case ccui.Widget.LOCAL_TEXTURE:
127                 bgBoxRenderer.initWithFile(backGround);
128                 break;
129             case ccui.Widget.PLIST_TEXTURE:
130                 bgBoxRenderer.initWithSpriteFrameName(backGround);
131                 break;
132             default:
133                 break;
134         }
135 
136         this.updateColorToRenderer(bgBoxRenderer);
137         this.updateAnchorPoint();
138         this.updateFlippedX();
139         this.updateFlippedY();
140         if(!bgBoxRenderer.textureLoaded()){
141             this._backGroundBoxRenderer.setContentSize(this._customSize);
142             bgBoxRenderer.addLoadedEventListener(function(){
143                 this.backGroundTextureScaleChangedWithSize();
144             },this);
145         }
146         this.backGroundTextureScaleChangedWithSize();
147     },
148     /**
149      * Load backGroundSelected texture for checkbox.
150      * @param {String} backGroundSelected
151      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
152      */
153     loadTextureBackGroundSelected: function (backGroundSelected, texType) {
154         if (!backGroundSelected) {
155             return;
156         }
157         texType = texType || ccui.Widget.LOCAL_TEXTURE;
158         this._backGroundSelectedFileName = backGroundSelected;
159         this._backGroundSelectedTexType = texType;
160         switch (this._backGroundSelectedTexType) {
161             case ccui.Widget.LOCAL_TEXTURE:
162                 this._backGroundSelectedBoxRenderer.initWithFile(backGroundSelected);
163                 break;
164             case ccui.Widget.PLIST_TEXTURE:
165                 this._backGroundSelectedBoxRenderer.initWithSpriteFrameName(backGroundSelected);
166                 break;
167             default:
168                 break;
169         }
170         this.updateColorToRenderer(this._backGroundSelectedBoxRenderer);
171         this.updateAnchorPoint();
172         this.updateFlippedX();
173         this.updateFlippedY();
174         this.backGroundSelectedTextureScaleChangedWithSize();
175     },
176 
177     /**
178      * Load cross texture for checkbox.
179      * @param {String} cross
180      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
181      */
182     loadTextureFrontCross: function (cross, texType) {
183         if (!cross) {
184             return;
185         }
186         texType = texType || ccui.Widget.LOCAL_TEXTURE;
187         this._frontCrossFileName = cross;
188         this._frontCrossTexType = texType;
189         switch (this._frontCrossTexType) {
190             case ccui.Widget.LOCAL_TEXTURE:
191                 this._frontCrossRenderer.initWithFile(cross);
192                 break;
193             case ccui.Widget.PLIST_TEXTURE:
194                 this._frontCrossRenderer.initWithSpriteFrameName(cross);
195                 break;
196             default:
197                 break;
198         }
199         this.updateColorToRenderer(this._frontCrossRenderer);
200         this.updateAnchorPoint();
201         this.updateFlippedX();
202         this.updateFlippedY();
203         this.frontCrossTextureScaleChangedWithSize();
204     },
205 
206     /**
207      * Load backGroundDisabled texture for checkbox.
208      * @param {String} backGroundDisabled
209      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
210      */
211     loadTextureBackGroundDisabled: function (backGroundDisabled, texType) {
212         if (!backGroundDisabled) {
213             return;
214         }
215         texType = texType || ccui.Widget.LOCAL_TEXTURE;
216         this._backGroundDisabledFileName = backGroundDisabled;
217         this._backGroundDisabledTexType = texType;
218         switch (this._backGroundDisabledTexType) {
219             case ccui.Widget.LOCAL_TEXTURE:
220                 this._backGroundBoxDisabledRenderer.initWithFile(backGroundDisabled);
221                 break;
222             case ccui.Widget.PLIST_TEXTURE:
223                 this._backGroundBoxDisabledRenderer.initWithSpriteFrameName(backGroundDisabled);
224                 break;
225             default:
226                 break;
227         }
228         this.updateColorToRenderer(this._backGroundBoxDisabledRenderer);
229         this.updateAnchorPoint();
230         this.updateFlippedX();
231         this.updateFlippedY();
232         this.backGroundDisabledTextureScaleChangedWithSize();
233     },
234 
235     /**
236      * Load frontCrossDisabled texture for checkbox.
237      * @param {String} frontCrossDisabled
238      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
239      */
240     loadTextureFrontCrossDisabled: function (frontCrossDisabled, texType) {
241         if (!frontCrossDisabled) {
242             return;
243         }
244         texType = texType || ccui.Widget.LOCAL_TEXTURE;
245         this._frontCrossDisabledFileName = frontCrossDisabled;
246         this._frontCrossDisabledTexType = texType;
247         switch (this._frontCrossDisabledTexType) {
248             case ccui.Widget.LOCAL_TEXTURE:
249                 this._frontCrossDisabledRenderer.initWithFile(frontCrossDisabled);
250                 break;
251             case ccui.Widget.PLIST_TEXTURE:
252                 this._frontCrossDisabledRenderer.initWithSpriteFrameName(frontCrossDisabled);
253                 break;
254             default:
255                 break;
256         }
257         this.updateColorToRenderer(this._frontCrossDisabledRenderer);
258         this.updateAnchorPoint();
259         this.updateFlippedX();
260         this.updateFlippedY();
261         this.frontCrossDisabledTextureScaleChangedWithSize();
262     },
263 
264     onTouchEnded: function (touch , event) {
265         var touchPoint = touch.getLocation();
266         this._touchEndPos.x = touchPoint.x;
267         this._touchEndPos.y = touchPoint.y;
268         if (this._focus) {
269             this.releaseUpEvent();
270             if (this._isSelected) {
271                 this.setSelectedState(false);
272                 this.unSelectedEvent();
273             }
274             else {
275                 this.setSelectedState(true);
276                 this.selectedEvent();
277             }
278         }
279         this.setFocused(false);
280         var widgetParent = this.getWidgetParent();
281         if(widgetParent){
282             widgetParent.checkChildInfo(2, this, touchPoint);
283         }
284     },
285 
286     onPressStateChangedToNormal: function () {
287         this._backGroundBoxRenderer.setVisible(true);
288         this._backGroundSelectedBoxRenderer.setVisible(false);
289         this._backGroundBoxDisabledRenderer.setVisible(false);
290         this._frontCrossDisabledRenderer.setVisible(false);
291     },
292 
293     onPressStateChangedToPressed: function () {
294         this._backGroundBoxRenderer.setVisible(false);
295         this._backGroundSelectedBoxRenderer.setVisible(true);
296         this._backGroundBoxDisabledRenderer.setVisible(false);
297         this._frontCrossDisabledRenderer.setVisible(false);
298     },
299 
300     onPressStateChangedToDisabled: function () {
301         this._backGroundBoxRenderer.setVisible(false);
302         this._backGroundSelectedBoxRenderer.setVisible(false);
303         this._backGroundBoxDisabledRenderer.setVisible(true);
304         this._frontCrossRenderer.setVisible(false);
305         if (this._isSelected) {
306             this._frontCrossDisabledRenderer.setVisible(true);
307         }
308     },
309 
310     setSelectedState: function (selected) {
311         if (selected == this._isSelected) {
312             return;
313         }
314         this._isSelected = selected;
315         this._frontCrossRenderer.setVisible(this._isSelected);
316     },
317 
318     getSelectedState: function () {
319         return this._isSelected;
320     },
321 
322     selectedEvent: function () {
323         if (this._checkBoxEventListener && this._checkBoxEventSelector) {
324             this._checkBoxEventSelector.call(this._checkBoxEventListener, this, ccui.CheckBox.EVENT_SELECTED);
325         }
326     },
327 
328     unSelectedEvent: function () {
329         if (this._checkBoxEventListener && this._checkBoxEventSelector) {
330             this._checkBoxEventSelector.call(this._checkBoxEventListener, this, ccui.CheckBox.EVENT_UNSELECTED);
331         }
332     },
333 
334     /**
335      * add event listener
336      * @param {Function} selector
337      * @param {Object} target
338      */
339     addEventListenerCheckBox: function (selector, target) {
340         this._checkBoxEventSelector = selector;
341         this._checkBoxEventListener = target;
342     },
343 
344     updateFlippedX: function () {
345         this._backGroundBoxRenderer.setFlippedX(this._flippedX);
346         this._backGroundSelectedBoxRenderer.setFlippedX(this._flippedX);
347         this._frontCrossRenderer.setFlippedX(this._flippedX);
348         this._backGroundBoxDisabledRenderer.setFlippedX(this._flippedX);
349         this._frontCrossDisabledRenderer.setFlippedX(this._flippedX);
350     },
351 
352     updateFlippedY: function () {
353         this._backGroundBoxRenderer.setFlippedY(this._flippedY);
354         this._backGroundSelectedBoxRenderer.setFlippedY(this._flippedY);
355         this._frontCrossRenderer.setFlippedY(this._flippedY);
356         this._backGroundBoxDisabledRenderer.setFlippedY(this._flippedY);
357         this._frontCrossDisabledRenderer.setFlippedY(this._flippedY);
358     },
359 
360     /**
361      * override "setAnchorPoint" of widget.
362      * @param {cc.Point|Number} point The anchor point of UICheckBox or The anchor point.x of UICheckBox.
363      * @param {Number} [y] The anchor point.y of UICheckBox.
364      */
365     setAnchorPoint: function (point, y) {
366         if(y === undefined){
367 	        ccui.Widget.prototype.setAnchorPoint.call(this, point);
368 	        this._backGroundBoxRenderer.setAnchorPoint(point);
369 	        this._backGroundSelectedBoxRenderer.setAnchorPoint(point);
370 	        this._backGroundBoxDisabledRenderer.setAnchorPoint(point);
371 	        this._frontCrossRenderer.setAnchorPoint(point);
372 	        this._frontCrossDisabledRenderer.setAnchorPoint(point);
373         }else{
374 	        ccui.Widget.prototype.setAnchorPoint.call(this, point, y);
375 	        this._backGroundBoxRenderer.setAnchorPoint(point, y);
376 	        this._backGroundSelectedBoxRenderer.setAnchorPoint(point, y);
377 	        this._backGroundBoxDisabledRenderer.setAnchorPoint(point, y);
378 	        this._frontCrossRenderer.setAnchorPoint(point, y);
379 	        this._frontCrossDisabledRenderer.setAnchorPoint(point, y);
380         }
381     },
382 	_setAnchorX: function (value) {
383 		ccui.Widget.prototype._setAnchorX.call(this, value);
384 		this._backGroundBoxRenderer._setAnchorX(value);
385 		this._backGroundSelectedBoxRenderer._setAnchorX(value);
386 		this._backGroundBoxDisabledRenderer._setAnchorX(value);
387 		this._frontCrossRenderer._setAnchorX(value);
388 		this._frontCrossDisabledRenderer._setAnchorX(value);
389 	},
390 	_setAnchorY: function (value) {
391 		ccui.Widget.prototype._setAnchorY.call(this, value);
392 		this._backGroundBoxRenderer._setAnchorY(value);
393 		this._backGroundSelectedBoxRenderer._setAnchorY(value);
394 		this._backGroundBoxDisabledRenderer._setAnchorY(value);
395 		this._frontCrossRenderer._setAnchorY(value);
396 		this._frontCrossDisabledRenderer._setAnchorY(value);
397 	},
398 
399     onSizeChanged: function () {
400         ccui.Widget.prototype.onSizeChanged.call(this);
401         this.backGroundTextureScaleChangedWithSize();
402         this.backGroundSelectedTextureScaleChangedWithSize();
403         this.frontCrossTextureScaleChangedWithSize();
404         this.backGroundDisabledTextureScaleChangedWithSize();
405         this.frontCrossDisabledTextureScaleChangedWithSize();
406     },
407 
408     /**
409      * override "getContentSize" method of widget.
410      * @returns {cc.Size}
411      */
412     getContentSize: function () {
413         return this._backGroundBoxRenderer.getContentSize();
414     },
415 	_getWidth: function () {
416 		return this._backGroundBoxRenderer._getWidth();
417 	},
418 	_getHeight: function () {
419 		return this._backGroundBoxRenderer._getHeight();
420 	},
421 
422     /**
423      * override "getVirtualRenderer" method of widget.
424      * @returns {cc.Node}
425      */
426     getVirtualRenderer: function () {
427         return this._backGroundBoxRenderer;
428     },
429 
430     backGroundTextureScaleChangedWithSize: function () {
431         if (this._ignoreSize) {
432             this._backGroundBoxRenderer.setScale(1.0);
433             var locBackSize = this._backGroundBoxRenderer.getContentSize();
434             this._size.width = locBackSize.width;
435             this._size.height = locBackSize.height;
436         }
437         else {
438             var textureSize = this._backGroundBoxRenderer.getContentSize();
439             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
440                 this._backGroundBoxRenderer.setScale(1.0);
441                 return;
442             }
443             var scaleX = this._size.width / textureSize.width;
444             var scaleY = this._size.height / textureSize.height;
445             this._backGroundBoxRenderer.setScaleX(scaleX);
446             this._backGroundBoxRenderer.setScaleY(scaleY);
447         }
448     },
449 
450     backGroundSelectedTextureScaleChangedWithSize: function () {
451         if (this._ignoreSize) {
452             this._backGroundSelectedBoxRenderer.setScale(1.0);
453         }
454         else {
455             var textureSize = this._backGroundSelectedBoxRenderer.getContentSize();
456             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
457                 this._backGroundSelectedBoxRenderer.setScale(1.0);
458                 return;
459             }
460             var scaleX = this._size.width / textureSize.width;
461             var scaleY = this._size.height / textureSize.height;
462             this._backGroundSelectedBoxRenderer.setScaleX(scaleX);
463             this._backGroundSelectedBoxRenderer.setScaleY(scaleY);
464         }
465     },
466 
467     frontCrossTextureScaleChangedWithSize: function () {
468         if (this._ignoreSize) {
469             this._frontCrossRenderer.setScale(1.0);
470         }
471         else {
472             var textureSize = this._frontCrossRenderer.getContentSize();
473             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
474                 this._frontCrossRenderer.setScale(1.0);
475                 return;
476             }
477             var scaleX = this._size.width / textureSize.width;
478             var scaleY = this._size.height / textureSize.height;
479             this._frontCrossRenderer.setScaleX(scaleX);
480             this._frontCrossRenderer.setScaleY(scaleY);
481         }
482     },
483 
484     backGroundDisabledTextureScaleChangedWithSize: function () {
485         if (this._ignoreSize) {
486             this._backGroundBoxDisabledRenderer.setScale(1.0);
487         }
488         else {
489             var textureSize = this._backGroundBoxDisabledRenderer.getContentSize();
490             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
491                 this._backGroundBoxDisabledRenderer.setScale(1.0);
492                 return;
493             }
494             var scaleX = this._size.width / textureSize.width;
495             var scaleY = this._size.height / textureSize.height;
496             this._backGroundBoxDisabledRenderer.setScaleX(scaleX);
497             this._backGroundBoxDisabledRenderer.setScaleY(scaleY);
498         }
499     },
500 
501     frontCrossDisabledTextureScaleChangedWithSize: function () {
502         if (this._ignoreSize) {
503             this._frontCrossDisabledRenderer.setScale(1.0);
504         }
505         else {
506             var textureSize = this._frontCrossDisabledRenderer.getContentSize();
507             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
508                 this._frontCrossDisabledRenderer.setScale(1.0);
509                 return;
510             }
511             var scaleX = this._size.width / textureSize.width;
512             var scaleY = this._size.height / textureSize.height;
513             this._frontCrossDisabledRenderer.setScaleX(scaleX);
514             this._frontCrossDisabledRenderer.setScaleY(scaleY);
515         }
516     },
517 
518     updateTextureColor: function () {
519         this.updateColorToRenderer(this._backGroundBoxRenderer);
520         this.updateColorToRenderer(this._backGroundSelectedBoxRenderer);
521         this.updateColorToRenderer(this._frontCrossRenderer);
522         this.updateColorToRenderer(this._backGroundBoxDisabledRenderer);
523         this.updateColorToRenderer(this._frontCrossDisabledRenderer);
524     },
525 
526     updateTextureOpacity: function () {
527         this.updateOpacityToRenderer(this._backGroundBoxRenderer);
528         this.updateOpacityToRenderer(this._backGroundSelectedBoxRenderer);
529         this.updateOpacityToRenderer(this._frontCrossRenderer);
530         this.updateOpacityToRenderer(this._backGroundBoxDisabledRenderer);
531         this.updateOpacityToRenderer(this._frontCrossDisabledRenderer);
532     },
533 
534     /**
535      * Returns the "class name" of widget.
536      * @returns {string}
537      */
538     getDescription: function () {
539         return "CheckBox";
540     },
541 
542     createCloneInstance: function () {
543         return ccui.CheckBox.create();
544     },
545 
546     copySpecialProperties: function (uiCheckBox) {
547         this.loadTextureBackGround(uiCheckBox._backGroundFileName, uiCheckBox._backGroundTexType);
548         this.loadTextureBackGroundSelected(uiCheckBox._backGroundSelectedFileName, uiCheckBox._backGroundSelectedTexType);
549         this.loadTextureFrontCross(uiCheckBox._frontCrossFileName, uiCheckBox._frontCrossTexType);
550         this.loadTextureBackGroundDisabled(uiCheckBox._backGroundDisabledFileName, uiCheckBox._backGroundDisabledTexType);
551         this.loadTextureFrontCrossDisabled(uiCheckBox._frontCrossDisabledFileName, uiCheckBox._frontCrossDisabledTexType);
552         this.setSelectedState(uiCheckBox._isSelected);
553     }
554 });
555 
556 window._p = ccui.CheckBox.prototype;
557 
558 // Extended properties
559 /** @expose */
560 _p.selected;
561 cc.defineGetterSetter(_p, "selected", _p.getSelectedState, _p.setSelectedState);
562 
563 delete window._p;
564 
565 /**
566  * allocates and initializes a UICheckBox.
567  * @constructs
568  * @return {ccui.CheckBox}
569  * @example
570  * // example
571  * var uiCheckBox = ccui.CheckBox.create();
572  */
573 ccui.CheckBox.create = function () {
574     var uiCheckBox = new ccui.CheckBox();
575     if (uiCheckBox && uiCheckBox.init()) {
576         return uiCheckBox;
577     }
578     return null;
579 };
580 
581 // Constants
582 //CheckBoxEvent type
583 ccui.CheckBox.EVENT_SELECTED = 0;
584 ccui.CheckBox.EVENT_UNSELECTED = 1;
585 
586 //Render zorder
587 ccui.CheckBox.BOX_RENDERER_ZORDER = -1;
588 ccui.CheckBox.BOX_SELECTED_RENDERER_ZORDER = -1;
589 ccui.CheckBox.BOX_DISABLED_RENDERER_ZORDER = -1;
590 ccui.CheckBox.FRONT_CROSS_RENDERER_ZORDER = -1;
591 ccui.CheckBox.FRONT_CROSS_DISABLED_RENDERER_ZORDER = -1;
592