Externalizing ActionScript Code
ActionScript code can be saved in external text files
(which use the .as
extension by convention) or
.swf
files and
imported into a Flash document. By maintaining code in external
files, we facilitate the use of standard code libraries across many
projects. We can import external code into Flash using Import From
File, using the #include
directive, or using a
shared library.
Import From File (Author-Time Import)
While editing a .fla
file, we may bring code
into the Action panel’s Script pane using
Import From File, found under the
arrow button in the top-right corner of the Actions panel (see Figure 16.1). Import From File is a one-time operation
that copies the contents of the external file into the Actions panel,
replacing any script currently there. Code
imported via Import From File is not persistently linked to the
.fla
file in any way. To append or insert script
text instead of replacing it, you need to manually cut and paste the
text from an external text-editing application.
#include (Compile-Time Import)
When
we
export (compile) a
.swf
file from a .fla
file,
we may import code from an external text file using the
#include
directive. For information on using
#include
, see Part III.
Shared Library (Runtime Import)
To
import code from an external source
while a movie is actually playing, we must create a shared library
.swf
file with a movie clip containing the code to import. Runtime import offers the most flexible approach to sharing code ...
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.