Main Content

Events

Define and trigger events; create listeners that respond to events

Events are notices broadcast when some change or action occurs involving an object. Listeners define functions that execute when specific events occur. Classes can define and trigger events. MATLAB® can trigger predefined events when code accesses object properties.

Functions

eventsEvent names
notifyNotify listeners that event is occurring
addlistenerCreate event listener bound to event source
listenerCreate event listener without binding to event source
event.hasListenerDetermine if listeners exist for event

Classes

event.EventDataBase class for event data
event.ClassInstanceEventEvent data for InstanceCreated and InstanceDestroyed events
event.listenerClass defining listener objects
event.PropertyEventData for property events
event.proplistenerDefine listener object for property events

Topics

Events and Listeners

Implementing Listeners

  • Listener Callback Syntax
    Specify listener callbacks using function handles.
  • Callback Execution
    Errors in listener callbacks do not prevent execution of other listeners. However, the order of listener execution is not defined.
  • Listener Lifecycle
    MATLAB manages the lifecycle of listeners. For greater control of listener lifecycle, construct listener objects using the listener method instead of addlistener.
  • Determine If Event Has Listeners
    You can determine if there are listeners defined for a specific event and event source.

Property Listeners

Samples of Events and Listeners