how to detect object id or object info in touch event, where touch event registered with multiple object

local i=1;
local firstView1 = display.newGroup()
local firstView2 = display.newGroup()
local firstView3 = display.newGroup()

– to set the image with their image id for each group

local function create_Instances(groupView, X, Y)

local img=display.newImage(“custm.png”,X,Y);
img.id=i;
i=i+1;
groupView:insert(img)

end
– touch event where i m dragging the group

function onTouch(event)
local t=event.target;

if event.phase == “began” then

print(“Touch Began Event Fired…”);
local parent =t.parent;
parent:insert(t);
display.getCurrentStage():setFocus( t )
event.target.alpha = 0.5;
t.isFocus=true;

t.x0 = event.x - t.x
t.y0 = event.y - t.y

elseif t.isFocus then
if “moved” == event.phase then

t.x = event.x - t.x0
t.y = event.y - t.y0

elseif event.phase== “ended” or event.phase == “cancelled” then
print(“Touch Ended Event Fired…”);
event.target.alpha = 1;
display.getCurrentStage():setFocus(nil);
t.isFocus = false
end
end
return true;
end
–create_Instances of Views
create_Instances(firstView1,70,200);
create_Instances(firstView2,70,250);
create_Instances(firstView3,100,250);

–Registering touch event to the group object

firstView1:addEventListener(“touch”,onTouch);
firstView2:addEventListener(“touch”,onTouch);
firstView3:addEventListener(“touch”,onTouch);

here the problem is how do access the img.id of firstView1, or firstView2 or firstView3,in touch event… that is how to know that id of current object which is tapped or dragged [import]uid: 42177 topic_id: 8222 reply_id: 308222[/import]

I don’t remember off the top of my head, but try printing both event.name and event.source to see if that’s the information you need. [import]uid: 12108 topic_id: 8222 reply_id: 29317[/import]

Thanks for giving reply :slight_smile: … I know about event.source and event.name but here my problem is to identify the object tat is which group object is currently accessing the touch event or function and how can i access their property… Actually i have to change the image of that particular group… while dragging it to different region on screen… if you any other idea to do so please tell me… thanks [import]uid: 42177 topic_id: 8222 reply_id: 29813[/import]

Is there a reason you set the id on the image and not on the group? As in, instead of img.id=i couldn’t you do groupView.id=i

For future reference, when posting code use the < code > tags and indent, I could barely read that. Also, while they aren’t hurting anything you don’t need the semi-colons in Lua. [import]uid: 12108 topic_id: 8222 reply_id: 29834[/import]

You can use object property to identify each object in your group.

temp.myName = “temp”
temp.id = 1

here, I created custom object property “myName” and “id” and I can use it to identify them later in the event handler such as:

if event.other.myname == “temp” then
–do your thing
end

Is this what you were looking for? :smiley:
[import]uid: 13978 topic_id: 8222 reply_id: 30092[/import]