1. Computing

Referencing ActionScripts from an External File

By

Like PHP, Javascript, and several other languages, ActionScripts can be placed in an external file and referenced from within the main file as an include. Similar to those languages, these files also have their own extensions; where you might find a script.php or script.js file for a PHP or Javascript application, external actionscripts would be placed in a file with a *.as extension--naturally, short for ActionScripts.

The difference is that while you would have to upload a .php or .js include’s separate file to the same directory as your main file, you don’t need to do that for a .as file. The .as file only needs to be in the same directory as your .fla file when you’re publishing your .swf file; as it publishes and runs the script, it will be included in the final output.

So why is this useful? Sometimes you end up using the exact same code over and over again in a complicated series of ActionScripts; this can actually slow you down and make a tangled mess of your scripts while you’re working. If you take the duplicate code and place it in an external file, you can reference that chunk of scripts wherever you need to with a single simplified line.

Let’s create an example. To start off, open a new Flash file and create a movie clip symbol on your stage.

©2014 About.com. All rights reserved.