Can't call setFillColor on a group?

Hi all,

I’m trying to tint a collection of DisplayObjects to gray in one go, so I’m logically trying to call setFillColor() on the group they belong to, but it’s not working.  Here’s the simple test code I’m using:

local gg = display.newGroup();
local a = display.newImage(gg, “image.png”, true);
a.x = display.contentCenterX;
a.y = display.contentCenterY;
gg:insert(a);

Now, that works exactly as expected, my image is on the screen.  So, next I do:

gg:setFillColor(0.5);

That throws an exception:

attempt to call method ‘setFillColor’ (a nil value)

I also tried calling the method directly on the image:

a:setFillColor(0.5);

…and that works exactly as expected.

I’m not seeing anything in the docs that indicates this shouldn’t work, it looks like that method SHOULD be available on a GroupObject, but it doesn’t seem to be.  Am I doing something stupid here?  Or is this really not something I can do?

FYI, I just got the upgrade to Pro (thanks guys, going free is SWEEEEEEET!) so I don’t think this is a “not available at your tier level” thing either.  I also DO NOT have compatibility turned on, so 2.0 for me.

Any ideas?  Thanks!

Hi @fzammetti,

Sorry, but you can’t set fill color on an entire group of objects. However, you can set the fill on the objects at the time you create/insert them (you’re doing this already), or if you need to perform this later, you can loop over the children of the group using the “group.numChildren” property and assign a fill to them all via the loop.

Take care,

Brent

Ok, thanks Brent, that’s what I thought, at least I’m not going crazy :)  Yeah, looping through manually will work for my use case so I’ll do that, just wish it was a one-liner, but I can live with it.

Hi @fzammetti,

Sorry, but you can’t set fill color on an entire group of objects. However, you can set the fill on the objects at the time you create/insert them (you’re doing this already), or if you need to perform this later, you can loop over the children of the group using the “group.numChildren” property and assign a fill to them all via the loop.

Take care,

Brent

Ok, thanks Brent, that’s what I thought, at least I’m not going crazy :)  Yeah, looping through manually will work for my use case so I’ll do that, just wish it was a one-liner, but I can live with it.