Working with Movie Clips and Buttons > Using event methods > About assigning a function to an event method |
![]() ![]() ![]() |
About assigning a function to an event method
Most ActionScript methods do something specific when you call them. For example, the play
method of the MovieClip object moves the playhead forward in the Timeline. Event methods are special methods that don't do anything on their own. To use an event method, you must define a function and assign it to the method.
Once you've written the path to the event method, you use the equality operator (=
) to assign a function to that method. You can insert any code into the body of the function, just as you can write any code inside the on
or onClipEvent
actions. The following example defines a function that rotates a movie clip when the enterFrame
event is triggered:
box.onEnterFrame = function () { this._rotation += 2; };
It is correct syntax to place a semicolon (;
) after the curly brace that closes the function. This is because this code is actually one long statement that could be written in one line.
Note: You can also assign event methods to an object's prototype chain. For more information, see Creating inheritance.
![]() ![]() ![]() |