Chapter 12. Controlling Actions with Events
In the previous chapter, you learned how to use ActionScript to move, transform, and change parts of your animation. But when something happens is just as important as the action itself. For example, you may want a movie object to start playing as soon as the Web page opens, or you may want to let your viewer decide when to watch it. You use events to control the actions in your animation. It’s as if your ActionScript program tells Flash: “When this (event) happens, do this (action).” The classic example is a button on the stage. The action statement says something like: “When this button gets clicked, go to Frame 25 of the movie clip, and then start playing.” You provide the programming that puts the people who view your Flash creations in the driver’s seat. Using events and event handlers, you can send your programs off into the world on their own, confident that they’ll behave.
This chapter explains how to use ActionScript to detect events when they happen and how to get your animations to perform specific actions as a result. Unlike previous versions, ActionScript 3.0 has one single way of handling all kinds of events. So, once you learn the basics, you’re all set to handle any event.
How Events Work
There are many different types of events. Some events—like a mouse click—are triggered by the people viewing your animation. Other events are simply occurrences in a Flash animation—like a movie clip reaching the last frame. The button is ...
Get Flash CS4: The Missing Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.