Search code examples
actionscript-3include-path

Change the include path for ActionScript


I am working on a custom library for Flash ActionScript3, and I have a handful of functions that I would like to add to Array.prototype.

I placed the extension in a separate .as file within a folder in the library directory, but when I make the include call from my document class, it tries to execute the include relative to the .fla file's location, rather than the library's source path.

I have already added the lib path to the Source Path: values under ActionScript3 Advanced Settings, which works for my import statements.

How do I get the include path to be relative to the library's path?

dir structure:

flash/
  lib/libname/inc/array.as
  projectname/project.fla

include that doesn't work (but should):

include "libname/inc/array.as";

include that works, but isn't portable if I move the project to a different location:

include "../lib/libname/inc/array.as";

Solution

  • I had a realization about how I was calling the include directive.

    I had stored my document class in the same directory as the .fla file, because it's a class specific to the project. The document class contained the include directive, but the class that was actually using the extended Array functions was within lib/libname.

    Moving the include directive to the .as file that required the extended features allowed the include directive to be called relative to the location of the calling class, which allowed me to use include "../inc/array.as"; because the .as file was within lib/libname/utils/ClassName.as.

    So the answer to the issue is that the include path is relative to the location of the calling script, not the project. This means that any script within the library can include features from the library without issue, as the structure will be preserved.