
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
22
|
Chapter 1: A Gentle Introduction for Nonprogrammers
In natural language, this tells the interpreter, “When the mouse button is released
over the
rotateButton object, execute the rotate function.” The rotate function might
look like this:
function rotate ( ) {
this._parent._rotation = 45;
}
A function that is executed when an event occurs is known as a callback function.As
we’ll learn in Chapter 10, within a callback function, the keyword
this refers to the
object that defined the event handler (in our case, rotateButton). In the case of a but-
ton reacting to a mouseclick,
this refers to the button that was clicked. Using object-
oriented syntax, the movie clip in which the button resides is referred to as
this.
_parent
(the movie clip is the button’s _parent because it contains the button).
Finally, we set the rotation of the parent movie clip to 45 degrees by assigning 45 to
this._parent._rotation:
this._parent._rotation = 45;
This literally translates to, “Set the rotation of this button’s parent movie clip to 45
degrees.”
Our sample button event handler is commonly written more succinctly as:
rotateButton.onRelease = function ( ) {
this._parent._rotation = 45;
};
Event-based programs are always running an event loop, ready to react to the next
event. Events are crucial to interactivity. ...