Home > Articles

  • Print
  • + Share This
This chapter is from the book

Linked Scripts

I want to mention the topic of linked scripts here because it fits very well with the other topics mentioned this hour. Remember all the ActionScripting you did in the Actions panel? Anything you can type in that panel can be stored as text in a text file. Let me just show you how it works.

The options arrow in the Actions panel allows you to "Export as File..." any code you've created in Flash. You can also copy and paste from Flash's Actions panel into a text editor. Flash happens to be a convenient place to create ActionScript—it colors your text and has easy-to-use parameter drop-down menus, for example. But because Flash is almost identical to JavaScript, you may likely find that a third-party text editor will do almost as well. You can create a text file full of ActionScript by simply typing by hand into a text editor. It isn't terribly important how you get your ActionScript into a text file, but that's the first step to using linked scripts.

After you've created your text file full of ActionScript, you can return to Flash. Use the Actions panel to select the Action "include" (under the plus button, Actions, Miscellaneous Actions) and specify, as its parameter, a named text file. For example, if in a keyframe you open the Actions panel and place the script #include "scripts.txt", Flash will use the contents of the file scripts.txt as if it were inside this keyframe. Presumably, the content of scripts.txt is a legitimate ActionScript. This is great because you can change the script without ever opening Flash. Just remember if you change the script file, you'll need to export the .swf again (as this is when the code is copied into Flash). This is a great feature.

One note: Macromedia suggests that you use ".as" as a file extension (instead of ".txt") so that everyone knows the file contains ActionScript. (Get it? The .as extension stands for ActionScript.)

Just like loadMovie and Shared Library items, external scripts let you modularize your projects for easy updates. The key is that you must plan for likely updates.

  • + Share This
  • 🔖 Save To Your Account