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

我试图在类函数中添加 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);
点赞
用户1276924
用户1276924

如果(phase.event=="began"),则应更改为:

if(event.phase=="began") then
2012-06-23 14:56:52