Event handlers for runtime objects
objects you create at runtime. For example, the following code creates a new movie clip
instance (
newclip_mc
this.attachMovie("symbolID", "newclip_mc", 10);
newclip_mc.onPress = function () {
trace("You pressed me");
}
For more information, see
Overriding event handler methods
you can override event handler methods with the functions that you write. You can define an
event handler in a new subclass that you can then reuse for various objects by linking any
symbol in the library of the extended class to the new subclass. The following code overrides
the MovieClip class's
of the movie clip:
// FadeAlpha class -- sets transparency when you click the movie clip.
class FadeAlpha extends MovieClip {
function onPress() {
this._alpha -= 10;
}
}
For specific instructions on extending an ActionScript class and linking to a symbol in the
library, see the examples in
information on writing and working with custom classes, see
Using event listeners
Event listeners let an object, called a listener object, receive events broadcast by another object,
called a broadcaster object. The broadcaster object registers the listener object to receive events
generated by the broadcaster. For example, you can register a movie clip object to receive
notifications from the Stage, or a button instance could receive
onResize
notifications from a text field object. You can register multiple listener objects to receive
events from a single broadcaster, and you can register a single listener object to receive events
from multiple broadcasters.
332
Handling Events
You can also assign functions to event handlers for
) and then assigns a function to the clip's
"Creating movie clips at runtime" on page
By creating a class that extends an ActionScript class,
event handler with a function that decreases the transparency
onPress
"Assigning a class to symbols in Flash" on page
event handler:
onPress
360.
279. For
Chapter 7, "Classes."
onChanged
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?