Lua中的警告对话框无法正常工作。

我正在使用 Gideros 中的 Lua,并且当按下返回按钮时出现警报框。根据 Gideros 文档,当第一个按钮被按下时,它返回索引 1,但实际上似乎并不是这样。我在我的安卓手机上测试了应用程序。我意识到 oncomplete 函数根本没有被调用,因为我尝试使用 print 语句,甚至它也没有被执行,所以有什么想法为什么没有被调用呢?

local function onKeyDown(event)
if event.keyCode == KeyCode.BACK then

        local alertDialog = AlertDialog.new("Confirmation", "Are you sure you want to exit?", "Cancel", "Yes")
        alertDialog:show()
        stage:addEventListener(Event.COMPLETE, oncomplete)
        end
end

function oncomplete(e)
if e.buttonIndex == 1 then
stage:addEventListener(Event.APPLICATION_SUSPEND, suspend)
application: exit()
end

end

function suspend()
application: exit()
end

-- key events are dispatched to all Sprite instances on the scene tree (similar to mouse and touch events)
stage:addEventListener(Event.KEY_DOWN, onKeyDown)
点赞
用户258523
用户258523

根据对话,问题是警报框关闭事件的事件侦听器附加到了舞台而不是警报对话框上。

stage:addEventListener(Event.COMPLETE, oncomplete)

而不是

alertDialog:addEventListener(Event.COMPLETE, oncomplete)

2014-05-07 20:36:04