Select an object and deselect and object

Hi
i am trying to create a function that, when i touch on this object i will do some code, something like:

local select = function()  
if (my block is selected by touch on this block) then ------\>("need to know how to do it")  
i will write some code  
elseif (my block is deselected by touch on another object or on the background) ------\>("need to know how to do it")  
i will write some code  

Thanks [import]uid: 26056 topic_id: 17819 reply_id: 317819[/import]

local obj1 = display.newRect(100,100, 10,10)
local obj2 = display.newRect(200,200, 10,10)

local function func(event)
if event.pahse==“ended” then
if event.target==obj1 then
– some code for object 1
elseif event.target==obj2 then
– some code for object 2
end
end
end

obj1:addEventListener(“touch”, func)
obj2:addEventListener(“touch”, func) [import]uid: 65903 topic_id: 17819 reply_id: 67999[/import]

Thanks aabweber, only one more doubt, i do:

if event.target==obj1 then
–some code
and what i need to use to do that:
when i touch on the background…some code, now not on objects on other think, now is on the background, if i touch on background i need to do some code but i cant make equal than objects.
to objects i use
if event.target==obj1 then

to background how i can make? [import]uid: 26056 topic_id: 17819 reply_id: 68016[/import]

put an object on the background (like, an image…?) and, in another elseif statement, check for it’s handler

elseif event.target== backGroundImage then -- some code for bg end [import]uid: 70635 topic_id: 17819 reply_id: 68021[/import]

i tryed it before and didnt work, but now i try it again and works perfectly

Thanks for all the help developers :slight_smile: [import]uid: 26056 topic_id: 17819 reply_id: 68028[/import]