如何在Lua中添加触摸事件监听器作为类函数?

时间:2012-06-22 08:32:56

标签: class lua corona addeventlistener

我正在尝试添加eventlistener并在类函数中使用它,但我无法成功。你能否分析我的代码并帮助我?

我的fish.lua课程:

 local class= {}

 function class.color(image)

 local color= display.newGroup();
 color=display.newImage(image)
 color:addEventListener("touch",class.listen)
 return color

end

function class.listen(event)
if(phase.event=="began") then
    print("hi")
 end
 end

return class

我的main.lua课程:

 local fishClass=require "fish" ;

 redfish="fish.small.red.png"
 local fish1=fishClass.color(redfish);

1 个答案:

答案 0 :(得分:1)

if(phase.event=="began") then

应该是:

if(event.phase=="began") then