1
目前谷歌搜索瘋狂只是爲了獲得一個非常簡單的(我希望)的方式來訪問一個單一的EventListener
訪問兩個或更多的功能的答案。用一個事件處理兩個函數。電暈的SDK
通過接收 發現這個
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)
卻不能管理它的工作,「運行時錯誤試圖concetrate場‘參數3’(函數值)」等。
我在做什麼錯?
你的參數是函數,而不是字符串。 (爲什麼要顯示函數?)不能連接函數。將它們轉換爲串聯之前的字符串:'「param1 =」.. tostring(t.param1)..' –
呃..我不知道... 還有什麼其他方式可以用一個eventlistener調用所有的3個函數? – Eyrik
要調用一個函數,你必須附加括號函數名:'使用functionName()' –