trace("this: " + this);
trace("myGrid: " + myGrid);
}
}
// register the myHandler function with myButton
// when the button is clicked, myHandler executes
function onLoad():Void{
myButton.addEventListener("click", myHandler);
}
}
Delegating events
You can import the
and functions. Use the following syntax:
import mx.utils.Delegate;
compInstance.addEventListener("eventName", Delegate.create(scopeObject,
function));
The
scopeObject
called.
There are two common uses for calling
•
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
the scope of the broadcaster component instance, not the object in which it is declared. See
"Delegating the scope of a function" on page
Delegating events to functions
Calling
Delegate.create()
same name. For example, if you have a check box and a button, you would have to use the
statement on the information you get from the
determine which component is broadcasting the
To use the following code, place a check box named
on the Stage. Select both instances and press F8 to create a new symbol. Click
myButton_btn
Advanced, Export for ActionScript, and enter the AS 2.0 class name Cart. You can give the new
symbol any instance name you want in the Property inspector. The symbol is now an instance of
the Cart class.
import mx.utils.Delegate;
import mx.controls.Button;
import mx.controls.CheckBox;
class Cart {
var myCheckBox_chb:CheckBox;
Delegate class
into your scripts or classes to delegate events to specific scopes
parameter specifies the scope in which the specified
Delegate.create()
is useful if you have two components that broadcast events of the
:
addEventListener()
65.
eventObject.target
event.
click
myCheckBox_chb
parameter is
function
, the function is invoked in
switch
property in order to
and a button named
Delegating events
63
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?
Questions and answers