我在循环中创建了一些按钮,我想获取该按钮的名称和标签。我已经在循环中设置了属性名称,那么如何在函数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
答案 0 :(得分:2)
试试这个
function selectCurrentColor(event)
print(event.target.tag)
print(event.target.name)
end