Changing Image for an Object

Hi,
I have an object declared
[lua]local image = display.newImage(“somepic.png”)[/lua]
and I also have some event handlers set on this object, so
[lua]local function=onTOuchEventHandler( event )
end
image:addEventHandler(“touch”,onTouchEventHandler)[/lua]

Now somewhere in the code, I need to change the image from somepic.png to thispic.png
I am missing the setImage equivalent, must be coz it’s past 1:00 in the morning

so what I am doing is

[lua]image:removeSelf() --Suicide
image = display.newImage(“thispic.png”) --Rebirth[/lua]

the issue with this is that the event handler is lost, so how can I change the image without losing the event handler??

cheers,

Jayant C Varma
[import]uid: 3826 topic_id: 3391 reply_id: 303391[/import]

Must not try to program after 11:00 pm and that too without Coffee or other such JOLT drinks.

It kind of worked out by itself. I guess the issue was

function changePic(event)  
obj:removeSelf()  
obj = display.newImage("thispic.png")  
obj:addEventListener("touch",onTouch)  
end  
  
function onTouch(event)  
end  
  
obj:addEventListener("touch",onTouch)  

The function was so placed that it was creating an error, so I created a blank function above the remove code and that worked.

cheers [import]uid: 3826 topic_id: 3391 reply_id: 10098[/import]

You could also use a global touch listener, instead of attaching it to the display object.

Tim [import]uid: 8196 topic_id: 3391 reply_id: 10113[/import]

Hi Tim,
I thought of it, but could not see a way to get the object clicked on.

I know that to check collision I can use the event.object1 and event.object2, are they the same that I can use for touches? (I guess I need to test it via code than asking)

is there a function equivalent to CGRectContainsPoint or the CGRectIntersection in Corona?

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3391 reply_id: 10230[/import]