Hello,
i would get the Url of the normalSprite from a Button, i use:
console.log(this.node.getComponent(cc.Button).normalSprite.nativeUrl);
but both of them give me : undefined
Where do i wrong?
Thank you
Hello,
i would get the Url of the normalSprite from a Button, i use:
console.log(this.node.getComponent(cc.Button).normalSprite.nativeUrl);
but both of them give me : undefined
Where do i wrong?
Thank you
âŚmmm do you have defined normalSprite?
you could use this:
if(this.node.normalSprite !== undefined && this.node.normalSprite !== null) console.log(this.node.normalSprite.nativeUrl);
I define it, but on the IDE
Isnât it enough?
the error is because ânormalSpriteâ inside this.node donât exists (https://docs.cocos.com/creator/api/en/classes/Node.html) but you could added with
this.node.normalSprite = âŚ
So, to get normalsprite from a button you could make this:
if(this.node.getComponent(cc.Button) !== undefined || this.node.getComponent(cc.Button) !== null)
{
var normalSprite = this.node.getComponent(cc.Button).normalSprite;
this.node.normalSprite = normalSprite; // save in node the normalSprite variable to future use
}
cc.Button -> https://docs.cocos.com/creator/api/en/classes/Button.html
remember, normalSprite is a spriteFrame https://docs.cocos.com/creator/api/en/classes/SpriteFrame.html
and inside you will find the ânativeUrlâ variable: https://docs.cocos.com/creator/api/en/classes/SpriteFrame.html#nativeurl
Cheers
No. Maybe I didnât explain myself correctly:
this.node.getComponent(cc.Button).normalSprite;
This doesnât work. It said: undefined
even if i set (like i showed in the image) the proprierties in the IDE
I had read from here https://github.com/cocos-creator/engine/blob/f495398f4307775f0f733162e3d128d81e063063/cocos2d/core/components/CCButton.js#L323 that âNormalâ (sprite-frame) is .normalSprite from the proprierties.
So why it doesnât show the .nativeUrl?
Thank you
I could suggest you to debug with chrome dev tools and see what value have this.node. (very strange).
Cheers.
What version of Creator are you using? Can you give us a demo that reproduces the problem?