类型 函数 库 system.* 返回值 EventDispatcher(事件调度器) 修订 版本 2024.3703 关键词 newEventDispatcher, event(事件)
返回一个新的 EventDispatcher(事件调度器),允许您设置自己的私有事件通信。与 Runtime(运行时) 和 DisplayObject(显示对象) 类型一样,这允许此 EventDispatcher(事件调度器) 的用户向其添加侦听器,并通过 object:dispatchEvent() 函数接收分派的自定义事件。
此 API 适用于希望添加类似于 Runtime:addEventListener() 和 Runtime:removeEventListener() 的自定义函数的插件开发者。
system.newEventDispatcher()
-- Create a private event dispatcher local eventDispatcher = system.newEventDispatcher() -- Add a listener to the above private event dispatcher -- Listens for an event named "custom" local function onCustomEvent( event ) print( "Received custom event!" ) end eventDispatcher:addEventListener( "custom", onCustomEvent ) -- Dipatch an event named "custom" -- Only listeners added to this dispatcher can receive it eventDispatcher:dispatchEvent( { name="custom" } )