Using Event Listeners - MACROMEDIA FLASH MX 2004-USING ACTIONSCRIPT IN FLASH Use Manual

Using actionscript in flash
Hide thumbs Also See for FLASH MX 2004-USING ACTIONSCRIPT IN FLASH:
Table of Contents

Advertisement

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 handlers for runtime objects
you create at runtime. For example, the following code creates a new movie clip instance
(
) and then assigns a function to the clip's
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
movie clip:
// FadeColor class -- fades color when movie clip is clicked
class FadeColor extends MovieClip {
function onPress() {
this._alpha = 30;
}
}
For specific instructions on extending an ActionScript 2.0 class and linking to a symbol in the
library, see the examples in

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.
"Creating movie clips at runtime" on page
event handler with a function that increases the transparency of the
onPress
"Assigning a class to a movie clip symbol" on page
You can also assign functions to event handlers for objects
onPress
By creating a class that extends an ActionScript 2.0 class,
event handler:
211.
218.
onChanged
Using event listeners
169

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents