1

目前用谷歌搜索自己疯了只是为了得到一个非常简单(我希望)的方法来访问两个或多个功能的答案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'(一个函数值)”等等。

我究竟做错了什么?

4

1 回答 1

0

我假设 timestampWrite 函数是这样定义的:

local timestampWrite = function()
    --some code here
end

这是代码:

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)

更多信息:

于 2013-05-27T21:01:31.710 回答