[Resolved] Set an image's color using a group

I would like to know how to do something like this:

local t={}  
for i=1, 10 do  
table.insert(t, display.newImage("myImage.png")  
end  
  
local function setImageColor()  
for i=1, 10 do  
t[i]:setFillColor(255, 0, 0)  
end  
end  
setImageColor()  

I’ve noticed that it will work if you put up in the setting up of the ‘t’ table ‘t[i]:setFillColor(255, 0, 0)’ but it won’t work in the function. How would I get it to work in the function? [import]uid: 147322 topic_id: 28342 reply_id: 328342[/import]

I’m sorry, I need to concentrate more on my posts. I used a table. What I mean is:

local t=display.newGroup()  
local a=display.newImage("myImage.png")  
t:insert(a)  
--do this several times  
  
local function setImageColor()  
for i=1, 10 do  
t[i]:setFillColor(255, 0, 0)  
end  
end  
setImageColor()  

[import]uid: 147322 topic_id: 28342 reply_id: 114481[/import]

Try running this code, replacing “smile.png” with your own image name;

[lua]local t=display.newGroup()
local a=display.newImage(“smile.png”)
a.x, a.y = 50, 100
t:insert(a)
local b=display.newImage(“smile.png”)
b.x, b.y = 100, 100
t:insert(b)
local c=display.newImage(“smile.png”)
c.x, c.y = 150, 100
t:insert©
–do this several times

local function setImageColor()
for i=1, t.numChildren do
t[i]:setFillColor(255, 0, 0)
end
end
setImageColor()[/lua]

Let me know if that works and if it doesn’t which version of Corona you are using, please.

Peach :slight_smile: [import]uid: 52491 topic_id: 28342 reply_id: 114589[/import]

Thank you so much! That worked. You can mark it as resolved now.

binc [import]uid: 147322 topic_id: 28342 reply_id: 114600[/import]

Not a problem, marking as resolved!

Peach :slight_smile: [import]uid: 52491 topic_id: 28342 reply_id: 114652[/import]