
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
The Multiple-Choice Quiz Revisited
|
213
The mark of good code is that it is modularized and centralized. Modules can be
replaced without affecting other modules or calls to the updated module. Further-
more, the code is in one central place that makes it easy to find and maintain. Impor-
tantly, there aren’t multiple scripts in which identical or nearly identical code is
repeated. Instead, function calls are used to perform operations that are centralized
in a library of generalized functions. Code modularity and centralization make it eas-
ier to reuse all or part of the code in other projects. Because functions can be exe-
cuted from other movie clips, they can be stored in a central location, easing code
maintenance and upgrades.
Suppose, for example, that we have three buttons in three different movie clips, all
with the same purpose. Instead of triplicating our code by adding it to each button,
we can put the code in a function on the main timeline and invoke it from each but-
ton as needed. This saves time, reduces the potential for errors, and makes it easy to
update the behavior of all three buttons at once. Because the code is centralized, test-
ing is more reliable, and troubleshooting is much easier. If one button works and a
second doesn’t, chances are that the problem is ...