简体   繁体   中英

Handling two functions with one event. Corona SDK

Currently googled myself insane just to get an answer on a pretty simple (I hope) way to access two or more functions at the touch of a single EventListener .

Found this

 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)

But have trouble managing it to work, by receiving "runtime error attempted to concetrate field 'param3' (a function value)" and so on.

What am I doing wrong?

I'm assuming timestampWrite functions are defined like this:

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

This is the code:

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)

More info:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM