Working with Movie Clips and Buttons > Using event methods |
![]() ![]() ![]() |
Using event methods
You can handle events using events methods that you can call from button and movie clip (as well as other object) instances in scripts anywhere in your document. If an object has event methods, they are located in the Events folders within each object folder in the Objects category in the Actions toolbox. You call an event method just as you would call any method, and then you assign a function to the method that tells Flash what to do when that event occurs. For example, the following code in Frame 1 of the main Timeline scales the ball
object when myButton
is clicked:
myButton.onPress = function () { _root.ball._xscale = 200; _root.ball._yscale = 200; };
Events that you handle with the on
and onClipEvent
actions don't conflict with event methods that you define. For example, if you attach an on (press)
action to a button that tells the movie to play, and define a function for the onPress
event for that same button that tells an object on the Stage to rotate when the button is clicked, the movie plays and the object rotates. Whether to use an event action or an event method is simply a matter of preferenceand they may be used together as well.
The following table lists movie clip events and corresponding movie clip event methods:
Event |
Event method |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onData |
The following table lists button events and corresponding button event methods:
Event |
Event method |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You can also use button events with movie clips to create movie clips that have all the powers of both movie clips and buttons. For more information about creating button movie clips, "Working with Movie Clips and Buttons" under Flash Help.
![]() ![]() ![]() |