【正文】
our code between different Flash applications. Therefore, it’ s important to follow best practices for coding when you create ActionScript in Flash. Rather than attaching your scripts to elements like keyframes, movie clips, and buttons, you should respond to events by calling functions that reside in a central location. One method is to attach embedded ActionScript to the first or second frame of the Timeline whenever possible so you don’ t have to search through the FLA file to find all your code. A mon practice is to create a layer called actions and place your ActionScript code there. When you attach all your scripts to individual elements, you’ re embedding all your code in the FLA file. If sharing your code between other Flash applications is important to you, use the Script window or your favorite text editor to create an external ActionScript (AS) file. By creating an external file, you make your code more modular and well anized. As your project grows, this convenience bees much more useful than you might imagine. An external file aids debugging and also source control management if you’ re working on a project with other developers. To use the ActionScript code contained in an external AS file, you create a script within the FLA file and then use the include statement to access the code you’ ve stored externally, as shown in the following example: include ../core/ You can also use ActionScript to create custom classes. You must store custom classes in external AS files and use import statements in a script to get the classes exported into the SWF file, instead of using include statements. You can also use ponents to share code and functionality. About writing scripts to handle events Events can be categorized into two major groups: those that occur on the Timeline (in keyframes) and those that occur on object instances (move clips, buttons, and other symbols). The interactivity of your Flash movie or application can be scattered over the many elements in your project, and you may be tempted to add scripts directly to these elements. However, Macromedia remends that you do not add scripts directly to these elements (keyframes and objects). Instead, you should respond to events by calling functions that reside in a central location. Using the Actions panel and Script window To create scripts that are part of your document, you enter ActionScript directly into the Actions panel. To create external scripts, you can use the Script window (File New ActionScript File) or your preferred text editor. When you use the Actions panel or Script window, you are using the ActionScript editor. Both the Actions panel and Script window have the Script pane (which is where you use the ActionScript editor) and the Actions toolbox. However, the Actions panel, and the Flash authoring environment in general, offer a few more codeassistance features than the Script window. Flash offers these features in the Actions panel because they are especially useful in the context of editing ActionScript within a FLA file. 。 and frame events, which occur within frames on the Timeline. Mouse and keyboard events A user interacting with your Flash movie or application triggers mouse and keyboard events. For example, when the user rolls o