簡體   English   中英

嘗試調用方法“ addEventListeners”(nil值)

[英]attempt to call method 'addEventListeners' (a nil value)

-這就是錯誤

-文件:menu.lua

Line: 131
--Attempt to call method 'addEventListeners' (a nil value)
--stack traceback:
--  menu.lua:131: in function 'startButtonListeners'
--  menu.lua:179: in function <menu.lua:32> --"startButtonListeners('add')"--
--  ?: in function 'dispatchEvent'
--  ?: in function 'gotoScene'

-我不明白我必須在哪里放置“ startButtonListeners('add')

local sceneGroup = self.view

background = display.newImageRect( "img/bg.png", display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0   

titleLogo = display.newImageRect( "img/title.png", 356, 132 )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = 150



-- button2
tasto2 = display.newImage('img/tasto2.png', 356,66)     
tasto2.x = display.contentWidth *0.5
tasto2.y = 300


sceneGroup:insert( background )
sceneGroup:insert( titleLogo )
sceneGroup:insert( tasto2 )


--listener "tap" 
function startButtonListeners(action)
    if (action == 'add')  then
        tasto2:addEventListeners ('tap', showInfo) --THIS IS LINE 131

    else
        tasto2:removeEventListeners ('tap', showInfo)

    end
end



function showInfo:tap(e)
        tasto2.isVisible = false
        titleLogo.isVisible = false
        infoView = display.newImage('img/bg.jpg', display.contentWidth *0.5, display.contentHeight *0.5)

        lastY = titleLogo.y

        transition.to(infoView, 
        {time = 400, 
        y = (display.contentHeight * 0.5) , 
        onComplete = function() 
        infoView:addEventListener('tap', hideInfo) end})
end


function hideInfo:tap(e) 
        transition.to(infoView, 
        {time = 300, 
        y = display.contentHeight + 25, 
        onComplete = function() 
            tasto2.isVisible = true
            titleLogo.isVisible = true`enter code here`
            infoView:removeEventListener('tap', hideInfo) 
            display.remove(infoView) infoView = nil end}) 
            transition.to(titleLogo, {time = 300, y = lastY}); 
end 
startButtonListeners('add')     

您是否嘗試過addEventListener? 我不認為addEventListeners是有效的函數...

可能是Corona無法從路徑加載圖像並返回nil嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM