quick 事件派发

local TestScene1 = class("TestScene1", function()
    return display.newScene("TestScene1")
end)


function TestScene1:ctor()
    cc(self):addComponent("components.behavior.EventProtocol"):exportMethods()

    local Common=require("src.app.scenes.Common")

    self:addEventListener(Common.PRINT_EVENT, function(event)
        print("print event")
    end)

    --派发一个事件
    self:dispatchEvent({name = Common.PRINT_EVENT})

end

return TestScene1
--这种方式非常值得学习,下次再导入外部函数的时候就可以使用了
local Common = class("Common")

Common.PRINT_EVENT="PRINT_EVENT"

return Common
原文地址:https://www.cnblogs.com/yufenghou/p/4474874.html