0

I seem to run into compile issues in Flash Builder when I import 3rd-party libraries at the wrong level in the directory structure.

For example, sometimes I'll import a library one level too deep into its directory tree, and the package explorer ends up excluding the prefix root-level package, usually "com." or "net.". Even though the content of the source itself doesn't change, this will cause compile errors.

Thus:

  • Is it a 1) convention or 2) language requirement that a class's package structure (e.g., "foo.bar.Class") must match its path location (e.g., foo/bar/Class.as)?

  • If it's a language requirement, why is it a requirement? Wouldn't that overdetermine the package structure, since it is already specified in the source code and quite happily consuming the first three to eight columns of each line?

  • If it's not a language requirement, are my compile errors just a result of Flash Builder enforcing the convention?

2
  • Sounds like you should go back and learn some fundamentals around AS3 and OOP. Have a good read of this - adobe.com/devnet/actionscript/articles/oop_as3.html
    – Adam Harte
    Jan 23, 2011 at 21:12
  • No doubt I'm pretty new to AS3, but I'm not sure if it's a requirement of OOP at large to double-specify packages (or their language-specific equivalents) in both source code and file structure. I see value in such a habit as a practical convention, but I guess I have to admit to feeling a bit of aesthetic discomfort at the idea that this is a compiler requirement. There are languages that can organize themselves without so much redundancy.
    – Jeff Lee
    Jan 24, 2011 at 7:41

1 Answer 1

1

It is a language requirement, and it's one that ActionScript shares with Java. The Wikipedia article on Java packages offers a fitting description:

The Java Language Specification establishes package naming conventions to avoid the possibility of two published packages having the same name. The naming conventions describe how to create unique package names, so that packages that are widely distributed will have unique namespaces. This allows packages to be separately, easily and automatically installed and catalogued.

I would add that by keeping the class files in a corresponding folder structure, it is possible to combine complete or partial projects (such as frameworks and/or components) by importing an existing folder structure - without the risk of naming conflicts and/or overwriting existing files. It also helps finding a particular class when you are working with large code bases.

2
  • I definitely see the logic there in having such conventions, but I'm curious: when the JLS refers to naming conventions, does it imply compiler requirements as well, or does it mean "convention" in the literal sense, i.e., standard practice but not a strict rule?
    – Jeff Lee
    Jan 24, 2011 at 7:30
  • 1
    I can see how this is misleading, but the quote is taken slightly out of context: The article is a bit longer, and it focuses mainly on how to name your packages (as in "which names should I pick?"). The term "convention" refers to that. Keeping a consistent file hierarchy is a requirement. Deviations will cause the compilation to fail. Jan 24, 2011 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.