How to get touched object?

Hi, guys!
I am quite new to Corona and i have some problem.
I have some image. And i want to spawn some text, when i touch the image. And if I touch anywhere else the text would disappear.
the first code i wrote was
[lua]local img = display.newCircle(100, 100, 25)
img.id = “circle”
local text = display.newText("", 200, 200, native.systemFont, 72)
img:setFillColor(255, 0, 0)
text:setTextColor(255, 0, 0)

local function test (event)
if event.target.id == “circle” then
text.text = “SDASDASDS”
else
text.text = “”
end
end
Runtime:addEventListener(“tap”, test)[/lua]

But then I saw, that if I add eventlistener to Runtime - I get NIL as event.target always. Is there a way to simply solve this problem? How to get the object, that was touched?
Thanks! [import]uid: 41345 topic_id: 8118 reply_id: 308118[/import]

Put an event listener on the circle that spawns the text, and put an event listener on Runtime to remove the text. [import]uid: 12108 topic_id: 8118 reply_id: 28902[/import]

If I do so - the text will be removed when I press on circle too…cause Runtime event will spawn with circle event…i think i need smth like event handling?(http://developer.anscamobile.com/content/application-programming-guide-event-handling#Propagation_and_Handling_of_Events)…but cant find good example [import]uid: 41345 topic_id: 8118 reply_id: 28906[/import]

Set the Runtime event listener in the circle event listener. That way it won’t run until the circle has been pressed first.

Also, if you have the circle event listener return true then the touch event won’t propagate down to Runtime, but like I said the most robust solution in this case is simply don’t set the Runtime listener until you actually want it.

function onCircle(event) --stuff happens Runtime.addEventListener("tap", onBackground) return true end function circle.addEventListener("tap", onCircle) [import]uid: 12108 topic_id: 8118 reply_id: 28927[/import]

Thanks, jhocking! This exactly what I search!
So, the final variant is:
[lua]local img = display.newCircle(100, 100, 25)
img.id = “circle”
local text = display.newText("", 200, 200, native.systemFont, 72)
img:setFillColor(255, 0, 0)
text:setTextColor(255, 0, 0)
local function onBackground(event)
if text.text ~= “” then
text.text = “”
end
end

local function onCircle(event)
if text.text == “” then
text.text = “SDFdsf”
end
Runtime:addEventListener(“tap”, onBackground)
return true
end

img:addEventListener(“tap”, onCircle)[/lua] [import]uid: 41345 topic_id: 8118 reply_id: 28933[/import]