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
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
[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]