Adding Scripts to Movie Clips
We’ve
already learned that we can attach
code to the frames of a movie clip’s timeline. It is also
possible to attach code to a movie clip object itself. To do so, we
select the movie clip instance on stage and then add our code to the
Script pane of the Actions panel. As with buttons, all code attached
to movie clip objects must be contained within event handlers. Event
handlers tell the interpreter when to execute the movie clip code.
For example, the following code sets the variable
x to 10 when a movie clip loads:
onClipEvent (load) {
var x = 10;
}Movie clip event handlers can react to mouse and keyboard activity, data loading, frames rendering, and the birth and death of movie clips. For complete coverage of movie clips and event handlers, see Chapter 10 and Chapter 13.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access