1"use strict";(self.webpackChunkrive_docs=self.webpackChunkrive_docs||[]).push([[36462],{1681:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>a,contentTitle:()=>s,default:()=>f,frontMatter:()=>o,metadata:()=>i,toc:()=>l});const i=JSON.parse('{"id":"Scripting/API Reference/interfaces/listener-action","title":"\u76d1\u542c\u5668\u52a8\u4f5c\u63a5\u53e3\uff08ListenerAction\uff09","description":"\u5f53\u5173\u8054\u7684 \u72b6\u6001\u673a\u76d1\u542c\u5668\uff08State Machine Listener\uff09 \u88ab\u89e6\u53d1\u65f6\u6267\u884c\u7684\u52a8\u4f5c\u3002","source":"@site/docs/Scripting/API Reference/interfaces/listener-action.md","sourceDirName":"Scripting/API Reference/interfaces","slug":"/Scripting/API Reference/interfaces/listener-action","permalink":"/docs/Scripting/API Reference/interfaces/listener-action","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"title":"\u76d1\u542c\u5668\u52a8\u4f5c\u63a5\u53e3\uff08ListenerAction\uff09"},"sidebar":"tutorialSidebar","previous":{"title":"\u5e03\u5c40\u63a5\u53e3\uff08Layout\uff09","permalink":"/docs/Scripting/API Reference/interfaces/layout"},"next":{"title":"\u8282\u70b9\u63a5\u53e3\uff08Node\uff09","permalink":"/docs/Scripting/API Reference/interfaces/node"}}');var r=t(74848),c=t(28453);const o={title:"\u76d1\u542c\u5668\u52a8\u4f5c\u63a5\u53e3\uff08ListenerAction\uff09"},s=void 0,a={},l=[{value:"\u65b9\u6cd5\uff08Methods\uff09",id:"\u65b9\u6cd5methods",level:2},{value:"<code>init</code>",id:"init",level:3},{value:"<code>perform</code>",id:"perform",level:3},{value:"<code>performAction</code>",id:"performaction",level:3}];function d(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",p:"p",pre:"pre",strong:"strong",...(0,c.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["\u5f53\u5173\u8054\u7684 ",(0,r.jsx)(n.a,{href:"/docs/Editor/State%20Machines/Listeners",children:"\u72b6\u6001\u673a\u76d1\u542c\u5668\uff08State Machine Listener\uff09"})," \u88ab\u89e6\u53d1\u65f6\u6267\u884c\u7684\u52a8\u4f5c\u3002"]}),"\n",(0,r.jsxs)(n.p,{children:["\u66f4\u591a\u4fe1\u606f\u89c1\uff1a",(0,r.jsx)(n.a,{href:"/docs/Scripting/Protocols/Listener%20Action%20Scripts",children:"Listener Action Scripts"})]}),"\n",(0,r.jsx)(n.h2,{id:"\u65b9\u6cd5methods",children:"\u65b9\u6cd5\uff08Methods\uff09"}),"\n",(0,r.jsx)(n.h3,{id:"init",children:(0,r.jsx)(n.code,{children:"init"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-lua",children:"init(self: T, context: Context) -> boolean\n"})}),"\n",(0,r.jsx)(n.p,{children:"\u76d1\u542c\u5668\u521b\u5efa\u6216\u9644\u52a0\u65f6\u8c03\u7528\u4e00\u6b21\u3002"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-lua",metastring:"highlight={4,5,6,12}",children:"type MyListenerAction = {}\n\n-- Called once when the script initializes.\nfunction init(self: MyListenerAction, context: Context): boolean\n return true\nend\n\nfunction perform(self: MyListenerAction, pointerEvent: PointerEvent) end\n\nreturn function(): ListenerAction<MyListenerAction>\n return {\n init = init,\n perform = perform,\n }\nend\n"})}),"\n",(0,r.jsx)(n.h3,{id:"perform",children:(0,r.jsx)(n.code,{children:"perform"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-lua",children:"perform(self: T, pointerEvent: PointerEvent) -> ()\n"})}),"\n",(0,r.jsxs)(n.p,{children:["\u5173\u8054\u7684 ",(0,r.jsx)(n.a,{href:"/docs/Editor/State%20Machines/Listeners",children:"\u72b6\u6001\u673a\u76d1\u542c\u5668\uff08State Machine Listener\uff09"})," \u89e6\u53d1\u65f6\u8c03\u7528\u3002\n\u8be5\u65b9\u6cd5\u5305\u542b ",(0,r.jsx)(n.a,{href:"/docs/Scripting/API%20Reference/artboards/pointer-event",children:"PointerEvent"})," \u53c2\u6570\uff0c\u63cf\u8ff0\u89e6\u53d1\u4ea4\u4e92\u7684\u7ec6\u8282\u3002"]}),"\n",(0,r.jsxs)(n.p,{children:[(0,r.jsx)(n.strong,{children:"\u5df2\u5f03\u7528\u3002"})," \u8bf7\u6539\u7528\u5e26 ",(0,r.jsx)(n.a,{href:"/docs/Scripting/API%20Reference/artboards/listener-context",children:"ListenerContext"})," \u7684 ",(0,r.jsx)(n.code,{children:"performAction"}),"\uff1b\u6b64\u91cd\u8f7d\u53ef\u80fd\u4f1a\u88ab\u79fb\u9664\u3002"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-lua",metastring:"highlight={9,10,11,17}",children:"type MyListenerAction = {}\n\nfunction init(self: MyListenerAction, context: Context): boolean\n return true\nend\n\n-- Add your transition logic here.\nfunction perform(self: MyListenerAction, pointerEvent: PointerEvent)\n -- perform action here\nend\n\n-- Return a factory function that Rive uses to build the Listener Action instance.\nreturn function(): ListenerAction<MyListenerAction>\n return {\n init = init,\n perform = perform,\n }\nend\n"})}),"\n",(0,r.jsx)(n.h3,{id:"performaction",children:(0,r.jsx)(n.code,{children:"performAction"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-lua",children:"performAction(self: T, listenerContext: ListenerContext) -> ()\n"})}),"\n",(0,r.jsxs)(n.p,{children:["\u5173\u8054\u7684 ",(0,r.jsx)(n.a,{href:"/docs/Editor/State%20Machines/Listeners",children:"\u72b6\u6001\u673a\u76d1\u542c\u5668\uff08State Machine Listener\uff09"})," \u89e6\u53d1\u65f6\u8c03\u7528\u3002\n\u8be5\u65b9\u6cd5\u5305\u542b ",(0,r.jsx)(n.a,{href:"/docs/Scripting/API%20Reference/artboards/listener-context",children:"ListenerContext"})," \u53c2\u6570\uff0c\u63cf\u8ff0\u89e6\u53d1\u4ea4\u4e92\u7684\u7ec6\u8282\u3002"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-lua",metastring:"highlight={7,8,9,10,11,12,18}",children:"type MyListenerAction = {}\n\nfunction init(self: MyListenerAction, context: Context): boolean\n return true\nend\n\n-- Called each time the listener fires.\nfunction performAction(self: MyListenerAction, listenerContext: ListenerContext)\n if listenerContext:isPointerEvent() then\n print('clicked')\n end\nend\n\n-- Return a factory function that Rive uses to build the Listener Action instance.\nreturn function(): ListenerAction<MyListenerAction>\n return {\n init = init,\n performAction = performAction,\n }\nend\n"})})]})}function f(e={}){const{wrapper:n}={...(0,c.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},28453:(e,n,t)=>{t.d(n,{R:()=>o,x:()=>s});var i=t(96540);const r={},c=i.createContext(r);function o(e){const n=i.useContext(c);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),i.createElement(c.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.