【正文】
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. Note: ActionScript code in external files is piled into a SWF file when you publish, export, test, or debug a FLA file. Therefore, if you make any changes to an external file, you must save the file and repile any FLA files that use it. When you write ActionScript in Flash 8, you use the Actions panel, the Script window, or both. When you use the Actions panel or Script window is dictated by how you respond to events, how you anize your code, and, most importantly, coding best practices. 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 11 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.