我在循环中创建了一些按钮,我想获取被点击的按钮的名称和标签。我已经在循环中设置了属性名称,所以如何在函数 selectCurrentColor 中获取名称和标签
这是我的代码:
for i=1,16 do
coloringSelect[i]=display.newImage("Resources/coloring_01/color" .. i .. ".png")
print("color" .. i .. ".png")
coloringSelect[i]:scale(0.28,0.28)
coloringSelect[i].x=colorx
coloringSelect[i].y=colory
coloringSelect[i].name= "color"..i
coloringSelect[i].tag= i
if i%2==0 then
colorx=40
colory=colory+30
else
colorx=colorx+38
end
stageGroup:insert( coloringSelect[i])
coloringSelect[i]:addEventListener("tap",selectCurrentColor)
end
function selectCurrentColor(self,event)
print(event.tag)
print(self.name)
end