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 に答える