首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试调用方法'addEventListeners‘(一个零值)

尝试调用方法'addEventListeners‘(一个零值)
EN

Stack Overflow用户
提问于 2014-10-21 12:57:02
回答 2查看 964关注 0票数 0

--这就是错误

-档案: menu.lua

代码语言:javascript
运行
复制
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')“放在哪里

代码语言:javascript
运行
复制
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')     
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-10-21 14:29:52

你试过addEventListener了吗?我认为addEventListeners不是一个有效的函数.

票数 3
EN

Stack Overflow用户

发布于 2014-10-21 13:41:19

可能是Corona从路径加载图像失败而返回0吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26487306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档