0

我将 Lua 与 Gideros 一起使用,并在按下后退按钮时显示警报框。根据 Gideros 文档,当按下第一个按钮时,它返回索引 1,但它似乎并没有真正以这种方式工作。我测试了应用程序我的android手机。我意识到oncomplete函数根本没有被调用,因为我尝试使用打印语句,甚至它没有被执行,所以知道为什么没有被调用吗?

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)
4

1 回答 1

1

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

stage:addEventListener(Event.COMPLETE, oncomplete)

代替

alertDialog:addEventListener(Event.COMPLETE, oncomplete)

于 2014-05-07T20:36:04.670 回答