Event.target?

I am using the following code

  
 local myObject = display.newImageRect( "wallpapers/1.png",320,480 )  
 myObject.x = \_W/5 -2  
 myObject.y = 130   
 myObject.xScale = .3  
 myObject.yScale = .3  
  
 local myObject2 = display.newImageRect( "wallpapers/2.png",320,480 )  
 myObject2.x = \_W/2  
 myObject2.y = 130  
 myObject2.xScale = .3  
 myObject2.yScale = .3  
  
 function click (event)  
 if(event.phase == "began") then  
 event.target:setFillColor(250,200,200)  
  
 end  
  
 end  
  
  
 myObject:addEventListener("touch", click)  
 myObject2:addEventListener("touch",click)  

I am trying to see which object is using the function by event.target, but that isn’t working. My whole objective here is to “highlight” which wallpaper is being pressed!
Thanks! [import]uid: 24708 topic_id: 26557 reply_id: 326557[/import]

Looks fine, to be honest.

what does this produce in the output?

[code]
local myObject = display.newImageRect( “wallpapers/1.png”,320,480 )
myObject.x = _W/5 -2
myObject.y = 130
myObject.xScale = .3
myObject.yScale = .3
myObject.thename = “object1”

local myObject2 = display.newImageRect( “wallpapers/2.png”,320,480 )
myObject2.x = _W/2
myObject2.y = 130
myObject2.xScale = .3
myObject2.yScale = .3
myObject2.thename = “object2”

function click (event)
local theobject
theobject = event.target
if(event.phase == “began”) then
event.target:setFillColor(250,200,200)
print (theobject.thename)
end

end

myObject:addEventListener(“touch”, click)
myObject2:addEventListener(“touch”,click)
[/code] [import]uid: 108660 topic_id: 26557 reply_id: 107684[/import]

Wouldn`t it be missing some return when closing the function?

as:

[lua]function click (event)
if(event.phase == “began”) then
event.target:setFillColor(250,200,200)
end
return true --<end
Cheers,
[import]uid: 89165 topic_id: 26557 reply_id: 107686[/import]

What build are you using? There’s a bug where certain methods don’t update the display properly.

Try this and see if it works.

[lua] if(event.phase == “began”) then
event.target:setFillColor(250,200,200)
event.target:translate(-1,-1)
event.target:translate(1,1)

end[/lua] [import]uid: 44647 topic_id: 26557 reply_id: 107692[/import]

Thanks Everyone for the speady replies!
Jeff - It did not have any errors and printed in the terminal as programmed

object1
object2

but did not change the color of the picture… I believe that this is because the object is not linking to the “event.target”. If i write print(event.target) is reads out in the terminal table: 0x1986150.
@RSCDEV - i tried putting return true into the function, but had no result.

toby2 - Version 2011.704 (2011.12.8) And the translate also had no result.

[import]uid: 24708 topic_id: 26557 reply_id: 107695[/import]

I just did some more testing and here is what i came up with

event.target:setFillColor(20,20,20)
does not work
event.target:setFillColor(20,20,20,100)
does not work – wasnt sure if the other value which i believe is alpha??

event.target.alpha = 0
DOES work
event.target.alpha = .2
does NOT work
it has to be something will the FillColor that does not work…

i also tried
local myObject = display.newImageRect( “wallpapers/1.png”,320,480 )
myObject.x = _W/5 -2
myObject.y = 130
myObject.xScale = .3
myObject.yScale = .3
myObject:setFillColor(20,20,20)

and that also worked…
[import]uid: 24708 topic_id: 26557 reply_id: 107697[/import]

Ahh im sorry guys i forgot to mention to you before that i am using scroll view
scrollView:insert( myObject )
scrollView:insert( myObject2) [import]uid: 24708 topic_id: 26557 reply_id: 107700[/import]

Exactly,
The fact that the object1 and object2 came out in debug proves that the event.target is giving you the correct objects.
So we’re down to ‘why doesn’t setFillColor do anything?’

does

theObject:setFillColor(255,0,0)
do anything if applied to the code that generates the debug output?
[import]uid: 108660 topic_id: 26557 reply_id: 107701[/import]

When i try the

theObject:setFillColor(255,0,0)

: attempt to index global ‘theObject’ (a nil value)
i think the reason it was not working before that i am also using scroll view… but i could be wrong! [import]uid: 24708 topic_id: 26557 reply_id: 107703[/import]

case sensitive.
The code has it as theobject not theObject
My bad. [import]uid: 108660 topic_id: 26557 reply_id: 107708[/import]

  
  
 -- Create an object and place it inside of ScrollView:  
 local myObject = display.newImageRect( "wallpapers/1.png",320,480 )  
 myObject.x = \_W/5 -2  
 myObject.y = 130   
 myObject.xScale = .3  
 myObject.yScale = .3  
 scrollView:insert( myObject )  
 local myObject2 = display.newImageRect( "wallpapers/2.png",320,480 )  
 myObject2.x = \_W/2  
 myObject2.y = 130  
 myObject2.xScale = .3  
 myObject2.yScale = .3  
 scrollView:insert( myObject2 )  
  
 function click (event)  
 theobject = event.target  
 if(event.phase == "began") then  
 theobject:setFillColor(20,20,20)  
  
 end  
  
 end  
  
  
 myObject:addEventListener("touch", click)  
 myObject2:addEventListener("touch", click)  

This does not work right now, but when i take them out of scroll view, they do work… Does scroll view not allow a color change?
[import]uid: 24708 topic_id: 26557 reply_id: 107710[/import]