• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Callback Functions

The traditional places to write scripts in Flash are in keyframes and on button or clip instances. In the case of buttons and clips, the main instructions would go within a specific mouse event (for buttons) or clip event (for clips). Placing code right on objects this way might seem intuitive because scripts are tied to the objects to which they pertain. However, this technique is limiting—even if it is a good way to learn.

The technique is limiting for several reasons. First, all your code is scattered in a million places. Code is easier to manage when it’s centralized. Second, some events (for which you want a script to respond) won’t fit neatly into the mouse event or clip event interface. For example, a clip’s data event is not nearly as clear and concrete as a button’s press event. It has gotten worse with all the new event triggers added to Flash MX. For example, Movie Clips now have 18 different clip events. Finally, many other types of objects also have events (for example, the TextField object’s onChanged event). There’s no interface to specify text events, however. Fortunately, by using callback functions, you can write scripts to respond to any built-in event—and the same technique works for any object (not just clips and buttons).


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint