@@ -233,13 +233,19 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{
233
233
* @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE } texType
234
234
*/
235
235
loadTextureNormal : function ( normal , texType ) {
236
- if ( ! normal ) return ;
237
-
236
+ if ( ! normal )
237
+ return ;
238
238
texType = texType || ccui . Widget . LOCAL_TEXTURE ;
239
239
this . _normalFileName = normal ;
240
240
this . _normalTexType = texType ;
241
241
242
+ var self = this ;
242
243
var normalRenderer = this . _buttonNormalRenderer ;
244
+ if ( ! normalRenderer . _textureLoaded ) {
245
+ normalRenderer . addEventListener ( "load" , function ( ) {
246
+ self . loadTextureNormal ( self . _normalFileName , self . _normalTexType ) ;
247
+ } ) ;
248
+ }
243
249
switch ( this . _normalTexType ) {
244
250
case ccui . Widget . LOCAL_TEXTURE :
245
251
//SetTexture cannot load resource
@@ -252,19 +258,14 @@ ccui.Button = ccui.Widget.extend(/** @lends ccui.Button# */{
252
258
default :
253
259
break ;
254
260
}
255
- var loaded = normalRenderer . _textureLoaded ;
256
- normalRenderer . removeEventListener ( 'load' , this . _loadNormalTextureCallback ) ;
257
- normalRenderer . addEventListener ( 'load' , this . _loadNormalTextureCallback , this ) ;
258
- if ( loaded ) {
259
- this . _loadNormalTextureCallback ( ) ;
260
- }
261
- } ,
262
- _loadNormalTextureCallback : function ( ) {
261
+
262
+ this . _normalTextureLoaded = normalRenderer . _textureLoaded ;
263
+
263
264
this . _normalTextureSize = this . _buttonNormalRenderer . getContentSize ( ) ;
264
265
this . _updateChildrenDisplayedRGBA ( ) ;
265
266
if ( this . _unifySize ) {
266
267
if ( this . _scale9Enabled ) {
267
- this . _buttonNormalRenderer . setCapInsets ( this . _capInsetsNormal ) ;
268
+ normalRenderer . setCapInsets ( this . _capInsetsNormal ) ;
268
269
this . _updateContentSizeWithTextureSize ( this . _getNormalSize ( ) ) ;
269
270
}
270
271
} else
0 commit comments