| MATLAB Function Reference | ![]() |
lh = event.listener(Hobj,'EventName',@CallbackFunction)
lh = event.listener(Hobj,'EventName',@CallbackFunction) creates a listener object for the named event on the specified object.
Listener objects respond to events. The event.listener class defines listener objects as a subclass of the handle class.
If delete is called on the listener object, the listener ceases to exist, which means the event no longer causes the listener callback function to execute. The listener can also be enabled or disabled by setting the value of the listener's Enabled property.
You can call the event.listener constructor instead of calling addlistener to create a listener. However, when you do not use addlistener, the listener's lifecycle is not tied to the object(s) being listened to.
| Property | Purpose |
|---|---|
| Source | Cell array of source objects |
| EventName | Name of the event |
| Callback | Function to execute when the event is triggered and the Enabled property is set to true |
| Enabled | callback executes when the event occurs if and only if Enabled is set to true (the default). |
| Recursive | When this property is set to true (the default), a listener can cause the same event that triggered the callback. This can lead to infinite recursion and the MATLAB®recursion limit eventually triggers an error to end the recursion. When set to false, this listener does not execute recursively. Therefore, if the callback triggers its own event, the listener does not execute again. |
addlistener, event.proplistener
![]() | event.PropertyEvent | event.proplistener | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |