Get url of child component of game object created with factory? (SOLVED)

My usecase:

I have a game object with just a sprite on it. I create this game object from a factory. I then need to animate its opacity. That’s tint.w on the child sprite (not on the game object itself). So question is, how do I access the sprite?

local piece = factory.create(msg.url("my_factory"), position)
local sprite_url = piece + "#sprite" -- This won't work since piece is a hash
go.animate(sprite_url, "tint.w", go.PLAYBACK_ONCE_FORWARD, 0.0, go.EASING_LINEAR, 0.4)

EDIT: I managed to do what I needed to do by placing a script on the game object and doing the animation there, but it feels like there should be a way to do it directly.

Best way I guess is to use msg.url()

local piece = factory.create(msg.url("my_factory"), position)    
local url = msg.url(piece)
url.fragment = "sprite"
go.animate(url, "tint.w", go.PLAYBACK_ONCE_FORWARD, 0.0, go.EASING_LINEAR, 0.4)
7 Likes

I didn’t know you can set the fragment on an url. Thanks!