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

Chapter 11. Manipulating Information > Building Reusable Scripts

Building Reusable Scripts

When you need to perform the same kind of manipulation of information multiple times, you can save time by building your own functions. The functions you've learned about so far, the getTimer, updateAfterEvent, and getProperty functions, are created and provided by Flash. Now with the action function, you can customize your own functions to perform specific tasks. Functions are pieces of reusable ActionScript statements that you put together and mix and match as needed. For example, in a task earlier in this chapter, you calculated the angle that a draggable movie clip makes with another movie-clip reference point. The ActionScript that computes the angle resides with the draggable movie clip. If you wanted to have multiple draggable movie clips the viewer could choose from, you would have to put the same ActionScript code in each of those movie clips. With functions, you would write the ActionScript that calculates the angle just once and put it on the root Timeline. Then each draggable movie clip could invoke, or call, that function whenever it needed to.

The following task builds a function that creates a sound object, attaches a sound, starts it, and sets the volume. By consolidating all these methods, you can play the sound with just one call to a single function, and do so multiple times from different places in your movie.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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