home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeActionScript: The Definitive GuideSearch this book

10.13. Copying Clip Event Handlers

A quick point that has major ramifications: movie clip event handlers are duplicated when a movie clip is duplicated via the duplicateMovieClip( ) function. Suppose, for example, we have a movie clip on stage called square, which has a load event handler defined:

onClipEvent (load) {
  trace("movie loaded");
}

What happens when we duplicate square to create square2?

square.duplicateMovieClip("square2", 0);

Because the load handler is copied to square2 when we duplicate square, the birth of square2 causes its load handler to execute, which displays "movie loaded" in the Output window. By using this automatic retention of handlers, we can create slick recursive functions with very powerful results. For a demonstration that only scratches the surface of what's possible, refer to Example 10-2.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.