简体   繁体   中英

attempt to call method 'addEventListeners' (a nil value)

--THIS IS THE ERROR

--File: 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'

-- I can't understand where I must put " 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')     

Have you tried addEventListener? I don't think addEventListeners is a valid function ...

可能是Corona无法从路径加载图像并返回nil吗?

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