jump to navigation

About setting and modifying the classpath in Flash CS3 August 14, 2010

Posted by Tournas Dimitrios in Flash.
trackback

In order to use a class or interface that you’ve defined, Flash must locate the external ActionScript files that contain the class or interface definition. The list of directories in which Flash searches for class and interface definitions is called the classpath.

When you create an ActionScript class file, you need to save the file to one of the directories specified in the classpath or a subdirectory therein. (You can modify the classpath to include the desired directory path). Otherwise, Flash won’t be able to resolve, that is, locate, the class or interface specified in the script. Subdirectories that you create within a classpath directory are called packages and let you organize your classes. (For more information on packages, see Creating and packaging your class files.)

Flash has two classpath settings: a global classpath and a document-level classpath. The global classpath is a classpath that’s shared by all of your Flash documents. The document-level classpath is a classpath that you specifically define for a single Flash document.

The global classpath applies to external ActionScript files and to FLA files, and you set it in the Preferences dialog box (Windows: Edit > Preferences (Windows) or Flash > Preferences (Macintosh), select ActionScript from the Category list, and then click ActionScript 3.0 Settings). You can set the document-level classpath in the Flash document’s Publish Settings dialog box (File > Publish Settings, select the Flash tab, and then click the Settings button).

When you click the Check Syntax button above the Script pane while editing an ActionScript file, the compiler looks only in the global classpath. ActionScript files aren’t associated with FLA files in Edit mode and don’t have their own classpath.

Using a global classpath :

The global classpath is a classpath that’s shared by all of your Flash documents.

You can modify the global classpath using the Preferences dialog box. To modify the document-level classpath setting, you use the Publish Settings dialog box for the FLA file. In both cases, you can add absolute directory paths (for example, C:/my_classes) and relative directory paths (for example, ../my_classes or “.”). The order of directories in the dialog box reflects the order in which they are searched.

By default, the global classpath contains one absolute path and one relative path. The absolute path is denoted by $(LocalData)/Classes in the Preferences dialog box. The location of the absolute path is shown here:

  • Windows: Hard Disk\Documents and Settings\user\Local Settings\Application Data\Adobe\Adobe Flash CS3\language\Configuration\Classes.
  • Macintosh: Hard Disk/Users/user/Library/Application Support/Adobe/Adobe Flash CS3/language/Configuration/Classes.

Do not delete the absolute global classpath. Flash uses this classpath to access built-in classes. If you accidentally delete this classpath, reinstate it by adding $(LocalData)/Classes as a new classpath.

The relative path portion of the global classpath is denoted by a single dot (.) and points to the current document directory. Be aware that relative classpaths can point to different directories, depending on the location of the document being compiled or published.

You can use the following steps to add a global classpath or edit an existing classpath.

To modify the global classpath:

  1. Select Edit > Preferences (Windows) or Flash > Preferences (Macintosh) to open the Preferences dialog box.
  2. Click the ActionScript in the left column, and then click the ActionScript 2.0 Settings button.
  3. Click the Browse to Path button to browse to the directory you want to add.
  4. Browse to the path that you want to add and click OK.

To delete a directory from the classpath:

  1. Select the path in the Classpath list.
  2. Click the Remove from Path button.

Do not delete the absolute global classpath. Flash uses this classpath to access built-in classes. If you accidentally delete this classpath, you can reinstate it by adding $(LocalData)/Classes as a new classpath.

or information on importing packages, see Working with packages.

Using a document-level classpath :

The document-level classpath applies only to FLA files. You set the document-level classpath in the Publish Settings dialog box for a particular FLA file (File > Publish Settings, then click the Flash tab, and then click ActionScript 2.0 Settings). The document-level classpath is empty by default. When you create and save a FLA file in a directory, that directory becomes a designated classpath directory.

When you create classes, in some cases you might want to store them in a directory that you then add to the list of global classpath directories in the following situations:

  • If you have a set of utility classes that all your projects use
  • If you want to check the syntax of your code (click the Check Syntax button) that’s within the external ActionScript file

Creating a directory prevents the loss of custom classes if you ever uninstall and reinstall Flash, especially if the default global classpath directory is deleted and overwritten, because you would lose any classes that you stored in that directory.

For example, you might create a directory such as the following for your custom classes:

  • Windows: Hard Disk\Documents and Settings\user\custom classes.
  • Macintosh: Hard Disk/Users/user/custom classes.

Then, you would add this path to the list of global classpaths (see Using a global classpath).

When Flash attempts to resolve class references in a FLA script, it first searches the document-level classpath specified for that FLA file. If Flash doesn’t find the class in that classpath, or if that classpath is empty, it searches the global classpath. If Flash doesn’t find the class in the global classpath, a compiler error occurs.

To modify the document-level classpath:

  1. Select File > Publish Settings to open the Publish Settings dialog box.
  2. Click the Flash tab.
  3. Click the Settings button next to the ActionScript Version pop-up menu.
  4. You can either manually type a file path or you can click the Browse to Path button to browse to the directory you want to add to the classpath.

To edit an existing classpath directory, select the path in the Classpath list, click the Browse to Path button, browse to the directory you want to add, and click OK.

To delete a directory from the classpath, select the path in the Classpath list, and click the Remove Selected Path (-) button.

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s