For example, suppose you have a button named next_btn on the Stage. The following code
assigns a function to the button's
to the next frame in the current timeline:
next_btn.onPress = function () {
nextFrame();
}
Assigning a function reference
assigned to an event handler for
an event handler method and later define the function, as shown in the following example:
// Assign a function reference to button's onPress event handler.
next_btn.onPress = goNextFrame;
// Define goNextFrame() function.
function goNextFrame() {
nextFrame();
}
Notice in the following example that you assign the function reference, not the function's
return value, to the
onPress
// Incorrect!
next_btn.onPress = goNextFrame();
// Correct.
next_btn.onPress = goNextFrame;
Receiving passed parameters
information about the event that occurred. For example, the
handler is invoked when a text field instance gains keyboard focus. This event handler receives
a reference to the text field object that previously had keyboard focus.
For example, the following code inserts some text into a text field that no longer has
keyboard focus:
this.createTextField("my_txt", 99, 10, 10, 200, 20);
my_txt.border = true;
my_txt.type = "input";
this.createTextField("myOther_txt", 100, 10, 50, 200, 20);
myOther_txt.border = true;
myOther_txt.type = "input";
myOther_txt.onSetFocus = function(my_txt:TextField) {
my_txt.text = "I just lost keyboard focus";
};
event handler; this function advances the playhead
onPress
In the previous code, the
. You can also assign a function reference (name) to
onPress
event handler:
Some event handlers receive passed parameters that provide
function is
nextFrame()
TextField.onSetFocus
Using event handler methods
event
331
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?