Lazy Loading of cc.Sprite defaults _isVisible to true and causes issues with cc.MenuItemImage._selectedImage

Due to the timing associated with asynchronous loading of images, when constructing a cc.MenuItemImage object, the *selectedImage.*isVisible property will spuriously be set to true inside of the “load” callback initialized in cc.Sprite.initWithFile.

Example:

call cc.MenuItemImage.create()
{
  calls cc.MenuItemImage.initWithNormalImage()
  {
    calls cc.Sprite.create(selectedImage, null, false);
    {
      calls cc.Sprite.initWithFile()   A
    }

    calls cc.MenuItemSprite.initWithNormalSprite
    {
      calls cc.MenuItemSprite.setSelectedImage(selectedSprite);
      {
        calls cc.MenuItemSprite._updateImagesVisibility();
      }
   }
  }
}

Now, cc.MenuItemImage_updateImagesVisibility() correctly sets *isVisible on all elements in the menuitem …
The problem is that inside cc.Sprite.initWithFile
<pre>
initWithFile:function {
cc.Assert:Invalid filename for sprite“);
var selfPointer = this;
var texture = cc.TextureCache.getInstance().textureForKey(filename);
if (!texture) {
//texture = cc.TextureCache.getInstance().addImage(filename);
this.*isVisible = false;
var loadImg = new Image;
loadImg.addEventListener {
if {
rect = cc.rect;
}
selfPointer.initWithTexture;
cc.TextureCache.getInstance.cacheImage;
selfPointer.isVisible = true; C
});
loadImg.addEventListener(”error“, function () {
cc.log(”load failure:" + filename);
});
loadImg.src = filename;
return true;
} else {
if {
if {
rect = cc.rect;
if
rect.size = texture.getContentSize;
else if || )
rect.size = cc.size;
}
return this.initWithTexture;
}
}
return false;
},
</pre>
Note the line at C. The
isVisible flag is being defaulted to true.

This causes problems because the outer code is setting this to false, and then this call which can happen later is setting this to true.

This causes the cc.MenuItemImage.*selectedImage.*isVisible to be true when it hasn’t been selected.

Hopefully this was a clear description of the issue.


Is this a known issue? Is there a workaround for this?

Many thanks

oh. this is bug. thanks very much. we will fixed come soon.

because asynchronous loading of images on web browser, so I hope you would preload image when use.