Main Content

event.hasListener

Determine if listeners exist for event

Description

tf = event.hasListener(src,EventName) returns true if listeners exist for the specified event on the object src. Otherwise, it returns false. When src is an array, event.hasListener returns a logical array the same size as src.

The class of src must define or inherit the specified event. If src is a heterogeneous array, the specified event must exist on the class of the array. event.hasListener cannot find listeners for events that are defined by some, but not all objects in the heterogeneous array.

event.hasListener respects the value of the event.listener object Enabled property. If you set the listener Enabled property to false, event.hasListener returns false for that listener.

example

Examples

collapse all

Determine if there are there listeners for MyEvent on object src:

tf = event.hasListener(src,'MyEvent');

If tf is true, then one or more listeners are attached to src for event MyEvent.

Input Arguments

collapse all

Event source, specified as a scalar or array of objects. The event source is the object to which the listener is attached.

Event name, specified as a char array.

Output Arguments

collapse all

true if listeners exist for the specified event on the specified objects. false if listeners do not exist.

Data Types: logical

Limitations

  • event.hasListener must have NotifyAccess for the event in question.

  • event.hasListener does not work with the predefined property events, PreSet, PostSet, PreGet, PostGet.

  • event.hasListener does not work with the predefined dynamic property events PropertyAdded and PropertyRemoved.

  • Use event.hasListener only with user-defined events.

Version History

Introduced in R2016a