Loading images from url

Hello,
cocos creator version is 2.4.4
I have checked this documentation
this is my code

@property(cc.Sprite)
profile: cc.Sprite = null;

let iconUrl = “http://www.something.com/something.png”;
cc.assetManager.loadAny({url: iconUrl, type: ‘png’}, function (err, texture) {
this.profile.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
});

But this produce error as

Uncaught TypeError: Cannot read property ‘getComponent’ of undefined

I’m not sure what is wrong with code.
Thank you

1 Like

Did you assign the node in the Creator interface? On the node that you have this code, drag the node that has the cc.Sprite into the property “profile”.

The problem error is that profile is void.

Also, did you changed the URL to some valid image?

1 Like

Yes I have assigned “profile” in Creator Creator

Screenshot (774)

this is the url “https://i.pinimg.com/originals/69/6b/8b/696b8b8aa775971c56533fca526c879f.png”

change “function (err, texture) {}” to “(err, texture) => {}”

or

add .bind(this) “function (err, texture) {}.bind(this)”

1 Like

hi, ‘profile’ is a component,not Node.

getComponent()

this is the method of the node
image