Class: handle
Create event listener bound to event source
el = addlistener(hSource,EventName,callback)
el = addlistener(hSource,PropertyName,EventName,callback)
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 |
To remove a listener, delete the listener object returned by addlistener
. For example,
delete(el)
calls the handle class delete method to delete the object from the workspace and remove the listener.
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 the event.listener
object. addlistener
ties the listener's lifecycle to the object that is the source of the event.
To define a listener that is not tied to the event object, use the event.listener
constructor directly to create the listener.
When you need the lifecycle of the listener object to be independent of the source object lifecycle, use listener
to create listeners.