addlistener
Class: handle
Create event listener bound to event source
Syntax
el = addlistener(hSource,EventName,callback)
el = addlistener(hSource,PropertyName,EventName,callback)
addlistener(___)
Description
creates a listener for the event el
= addlistener(hSource
,EventName
,callback
)EventName
when triggered on the source object, hSource
.
If hSource
is an array, the listener responds to the named event on any object in the hSource
array. callback
is a function handle referencing the callback function.
creates a listener for one of the predefined property events. There are four predefined
property events.el
= addlistener(hSource
,PropertyName
,EventName
,callback
)
Event Name | Event Occurs |
---|---|
PreSet | Immediately before the property value is set, before calling its set access method |
PostSet | Immediately after the property value is set |
PreGet | Immediately before a property value query is serviced, before calling its get access method |
PostGet | Immediately after returning the property value to the query |
addlistener(___)
creates a listener object without a
handle. You can use this syntax with any of the previous input syntaxes.
Input Arguments
Output Arguments
Examples
Tips
Redefining or clearing the variable containing the handle of the listener (for example,
el
) does not delete the listener. The event object (hSource
) still has a reference to theevent.listener
object.addlistener
ties the listener's lifecycle to the object that is the source of the event.Although the listener is bound to the lifecycle of the event source, the listener continues to exist after the event source is destroyed when:
One or more references to the listener are in other variables, including the handle of the listener if one was specified at creation.
The listener is tied to other event sources.
To remove a listener, delete the listener object returned by
addlistener
. For example,delete(el)
calls the handle class delete method to delete the listener object.To define a listener that is not tied to the event object, use the
event.listener
constructor directly to create the listener.
Alternatives
When you need the lifecycle of the listener object to be independent of the source object lifecycle, use listener
to create listeners.
Extended Capabilities
Version History
Introduced in R2008a