Listener Callback Syntax
In this section...
“Specifying Listener Callbacks” on page 11-30
“Input Arguments for Callback Function” on page 11-30
“Additional Arguments for Callback Function” on page 11-31Specifying Listener Callbacks
Callbacks are functions that execute when the listener receives notification of the event.
Pass a function handle referencing the callback function to handle.addlistener or
handle.listener when creating the listener.All callback functions must accept at least two arguments:- The handle of the object that is the source of the event
- An event.EventData object or an object that is derived from the event.EventData
class.
Syntax to Reference CallbackFor a function: functionName
lh = addlistener(eventSourceObj,'EventName',@functionName)For an ordinary method called with an object of the class: obj.methodName
lh = addlistener(eventSourceObj,'EventName',@obj.methodName)For a static method:ClassName.methodName
lh = addlistener(eventSourceObj,'EventName',@ClassName.methodName)For a function in a package:PackageName.functionName
lh = addlistener(eventSourceObj,'EventName',@PackageName.functionName)Input Arguments for Callback Function
Define the callback function to accept the required arguments:11 Events — Sending and Responding to Messages