Lua 自定义event,怎么处理dispatchEvent

下面的代码,没有执行测试的函数handleBuyGoods,是那里有问题

local MainScene = class(“MainScene”, cc.load(“mvc”).ViewBase)

MainScene.RESOURCE_FILENAME = “MainScene.csb”

–用于测试执行的函数
local function handleBuyGoods(event)
print(“handleBuyGoods”)
end

function MainScene:onCreate()
– 监听:
– 1.获取事件分发器 : EventDispatcher
local dispatcher = cc.Director:getInstance():getEventDispatcher()

-- 2.创建事件监听器  : EventListener 
local listener = cc.EventListenerCustom:create("kDidBuyGoods", handleBuyGoods)


-- 4.在事件分发器中,添加监听器。事件响应委托为
dispatcher:addEventListenerWithSceneGraphPriority(listener, self)


--测试事件  
local eventDispatcher = cc.Director:getInstance():getEventDispatcher()
local event = cc.EventCustom:new("kDidBuyGoods")
eventDispatcher:dispatchEvent(event) 


--问题是没有执行对应的函数啊

end

return MainScene

只要修改如下代码就可以
– 4.在事件分发器中,添加监听器。事件响应委托为
dispatcher:addEventListenerWithFixedPriority(listener, 1)

请参考lua-tests中NewEventDispatcherTest.lua的CustomEventTest测试例。