#include Versus Classpath
External ActionScript files are not new to Flash, but they were introduced differently in Flash 2004 and are brought in at compile time.In older versions of Flash, if you wanted to include an external AS file, you would use a pound sign (#) followed by the keyword include, and the path to the AS file as a string literal like this:
Notice that this line of code is not followed by a semicolon like most lines in ActionScript. An include statement cannot be followed by a semicolon or errors may occur. Also, do not put code directly below an include statement or errors might occur. Put at least one line of space between include statements and other code.That was the old way of including external ActionScript in Flash files and it will still work if you want to use it. However, the new way is much simpler and it is called classpath.The classpath is a path or group of paths to where external ActionScript files can be found. And to include information from within one of the files, you simply call the constructor of the object class and Flash will look for a reference to that object in the classpath.Here is an example of an external AS file:
#include "myFile.as"
And provided that this external AS file is within the classpath, the ActionScript to use it in Flash would be as follows:
class MyClass{
//class definition
}
When this action is called, it will look through the classpath to see if there is a class named MyClass in it (which incidentally will be a file named MyClass.as). You can also keep external AS files in the same directory as the Flash file that is trying to use them, and if the class being referred to in Flash cannot be found in the defined paths of the classpath, it will then look in its own directory, which is also controlled by the classpath.NOTEExternal ActionScript files are compiled directly into the SWF file when the SWF file is created, so if an external AS file is updated, the Flash file using it must be recompiled before the changes will take effect.You can set the classpath in your preferences by going to Edit>Preferences and choosing the ActionScript category (see Figure 18.2). Then choose the ActionScript 2.0 Settings button and the ActionScript Settings dialog box pops up as shown in Figure 18.3. Here you can add classpaths, remove them, or edit them. You can also sort the order in which they are checked. Notice that it has two directories by default. The first one listed is the ".", which represents the same directory as the Flash file you are working in. The second classpath is where Flash's built-in classes are keptin the Classes directory of the user's configuration directory.
var sampleClass:MyClass = new MyClass();
Figure 18.2. ActionScript preferences for all Flash documents.

Figure 18.3. ActionScript Settings dialog box where you can control your classpaths.

Figure 18.4. Publish settings for the Flash tab.

Figure 18.5. ActionScript settings for the publish settings.
