< Day Day Up > |
In order for a .fla file to access a class in a package, the root directory of the package must reside within the classpath . The classpath is simply the list of directories (paths) on your hard drive in which the compiler looks for classes. Entries in the classpath can be added globally for all documents (the global classpath ) or on a per- .fla file basis (a document classpath ). By default, the global classpath includes the following directories:
The Classes directory is found in one of the following locations, depending on your operating system. In each of the following paths, substitute your operating system user account name for USER and your Flash language code for LANGUAGE_CODE , which is "en" for English:
Because the default global classpath includes the current directory (.), every .fla file can access classes in the same directory as the .fla itself. Similarly, every .fla file can access classes in the /Configuration/Classes directory. You should not remove either of those directories from the global classpath. Furthermore, if the root directory of a package resides in either the same directory as the .fla file or in the /Configuration/Classes directory, then the classes in that package are accessible to the .fla file. For example, suppose that, on Windows XP, we create a document, game.fla and place it in the directory c:\data\projects\fungame . Then we create a class, com.yourdomain.game.Player and place its class file in: c:\data\projects\fungame\com\yourdomain\game\Player.as . Because game.fla and the root of the Player class's package reside in the same directory, game.fla finds the Player class successfully. // Given this directory setup, game.fla can access the Player class C:\data\projects\fungame\game.fla C:\data\projects\fungame\com\yourdomain\game\Player.as Likewise, if the class file for com.yourdomain.game.Player resides in the /Configuration/Classes directory, then game.fla (and, indeed, any .fla file) will find the Player class successfully. // Given this directory setup, game.fla can access the Player class C:\data\projects\fungame\game.fla C:\Documents and Settings\ USER \Local Settings\Application Data\ Macromedia\Flash MX 2004\ LANGUAGE_CODE \Configuration\Classes\com\yourdomain \game\Player.as If Player.as is not found in either of those locations, the compiler generates the following error: The class 'com.yourdomain.game.Player' could not be loaded.
9.3.1 Adding a New Directory to the ClasspathIf we want to store our Player.as class file in a directory other than the two included by default in the global classpath (and /Configuration/Classes ), we have to add the package root directory to either the global classpath or the document classpath (i.e., the classpath specified by game.fla itself). For example, suppose we were to place Player.as here: C:\data\actionscript\com\yourdomain\game\Player.as To give all .fla files access to the Player class, we'd add the directory C:\data\actionscript to the global classpath, as follows :
Alternatively, if we were using the Player class only in game.fla , we could give game.fla individual access to the Player class by adding the directory C:\data\actionscript to game.fla 's own classpath, like this:
Classpath entries can also be specified using relative paths, such as ./ for the directory that contains the .fla file, ../ for one directory up from the .fla file, ../../ for two directories up, and so on. For example, if your .fla file is stored in this location: C:\data\projects\fungame\movie\game.fla and the classes used by game.fla are stored in this location: C:\data\projects\fungame\classes you can grant game.fla access to the classes in the classes directory by specifying the following relative classpath: ../classes Relative classpaths are useful when sharing files across disparate filesystems or operating systems, as is common when working with a team or using version control software. |
< Day Day Up > |