User Guide
Delegating events 73
Delegating events
You can import the Delegate class into your scripts or classes to delegate events to specific
scopes and functions (see “Delegate class” in the Components Language Reference). To import
the Delegate class, use the following syntax:
import mx.utils.Delegate;
compInstance.addEventListener("eventName", Delegate.create(scopeObject,
function));
The scopeObject parameter specifies the scope in which the specified function parameter
is called.
There are two common uses for calling
Delegate.create():
■ To dispatch the same event to two different functions.
See the next section.
■ To call functions within the scope of the containing class.
When you pass a function as a parameter to
addEventListener(), the function is
invoked in the scope of the broadcaster component instance, not the object in which it is
declared. See “Delegating the scope of a function” on page 76.
Delegating events to functions
Calling Delegate.create() is useful if you have two components that broadcast events of
the same name. For example, if you have a check box and a button, you would have to use the
switch statement on the information you get from the eventObject.target property in
order to determine which component is broadcasting the
click event.