【发布时间】:2013-05-22 12:57:40
【问题描述】:
目前我疯狂地用谷歌搜索自己,只是为了得到一个非常简单(我希望)的方法来访问两个或多个功能,只需触摸一个 EventListener。
找到这个
local touchHandler = function(event)
if event.phase == "began" then
local t = event.target
print( "param1=" .. t.param1 .. ", param2=" .. t.param2 .. ", param3=" .. t.param3 )
end
end
local loadServerButton = display.newRect(0, 0, 50, 50)
loadServerButton:setFillColor(0, 0, 0)
loadServerButton.x= _W/2
loadServerButton.y= _H/1.35
loadServerButton.param1 = timestampWrite
loadServerButton.param2 = downloadServerAPI
loadServerButton.param3 = downloadUserAPI
loadServerButton:addEventListener("touch", touchHandler)
但是很难管理它的工作,通过接收 “运行时错误试图集中字段'param3'(一个函数值)”等等。
我做错了什么?
【问题讨论】:
-
您的参数是函数,而不是字符串。 (为什么要显示函数?)不能连接函数。在连接之前将它们转换为字符串:
"param1="..tostring(t.param1).. -
嗯..我不知道...我还能用一个事件监听器调用所有 3 个函数吗?
-
要调用一个函数,你必须在函数名后面加上括号:
functionname() -
function loadFuntions(event) timestampWrite() timestampWrite2() end 类似的东西?