Carousel Touch ?

Hi vovasoft,
that would make that event listener the same for all the icons in the table.
I need a method to have a different event listener for each icon in the table :slight_smile:
tyvm
[import]uid: 58922 topic_id: 36496 reply_id: 144815[/import]

[lua]function Icon(i)
local this = {}
local icon = display.newImage(carousel, ā€œimages/iconā€ā€¦i…".png")
icon.tag = i
icon :addEventListener(ā€œtouchā€, onIconTouch)
this.angle = (i-1) * math.rad(360/NUM_ITEMS);
this.img = icon
return this
end
[/lua]
Now you should control icon.tag in onIconTouch listener [import]uid: 138389 topic_id: 36496 reply_id: 144817[/import]

works perfectly, thank you vovasoft :slight_smile:

[lua]
function Icon(i)

local this = {}
local icon = display.newImage(carousel, ā€œimageā€ā€¦i…".png")
icon.tag = i
local function onIconTouch(event)
if icon.tag == 1 and event.phase == ā€œendedā€ then
print(ā€˜icon 1 touched’)
end
if icon.tag == 2 and event.phase == ā€œendedā€ then
print(ā€˜icon 2 touched’)
end
if icon.tag == 3 and event.phase == ā€œendedā€ then
print(ā€˜icon 3 touched’)
end
if icon.tag == 4 and event.phase == ā€œendedā€ then
print(ā€˜icon 4 touched’)
end
if icon.tag == 5 and event.phase == ā€œendedā€ then
print(ā€˜icon 5 touched’)
end
if icon.tag == 6 and event.phase == ā€œendedā€ then
print(ā€˜icon 6 touched’)
end
end
icon :addEventListener(ā€œtouchā€, onIconTouch)
icon.rotation = 20
this.angle = (i-1) * math.rad(360/NUM_ITEMS);
this.img = icon

return this
end
[/lua] [import]uid: 58922 topic_id: 36496 reply_id: 144822[/import]

try this:
[lua]
local function onIconTouch(event)
if event.phase == ā€œendedā€ then
if icon.tag == 1 then
print(ā€˜icon 1 touched’)
end
if icon.tag == 2 then
print(ā€˜icon 2 touched’)
end
if icon.tag == 3 then
print(ā€˜icon 3 touched’)
end
if icon.tag == 4 then
print(ā€˜icon 4 touched’)
end
if icon.tag == 5 then
print(ā€˜icon 5 touched’)
end
if icon.tag == 6 then
print(ā€˜icon 6 touched’)
end
end
end
[/lua] [import]uid: 138389 topic_id: 36496 reply_id: 144824[/import]

Yep, that works as well, tyvm [import]uid: 58922 topic_id: 36496 reply_id: 144827[/import]