3

Originally my classes(.as) and project (.fla) were stored in the same directory. But I would like to refactor them. I've created a subdirectory "classes", and moved my classes into this subdirectory but I've got error.

All my classes are stored in one package.

How can I "include" or "import" my classes from a subdirectory of my project?

Chris
  • 54,599
  • 30
  • 149
  • 186
takayoshi
  • 2,789
  • 5
  • 36
  • 56
  • Think of the package name of a class as being the names of the folders relative to the main class folder. So if you are in folder A with your FLA file, you have a sub folder "classes" and you have a class inside of "classes", then the package for this class would be "classes". If you had another sub folder "classes2" inside of "classes", with another class file within it (.as file), then the package of this second class could be "classes.classes2". So on and so forth. So this is basically just expanding a bit on dingo's answer to give examples relative to your current project. –  Mar 24 '11 at 11:04

2 Answers2

6

The problem is probably the .as files in the new folders. AS3 namespaces map to your filesystem. This means a class named Bar in the folder foo needs to be in the foo namespace.

Bar.as

package {

foo/Bar.as

package foo {

widget.as

package {
    import foo.Bar;

Which will look like this on your filesystem:

| Bar.as
- foo
   | Bar.as
| widget.as
DingoEatingFuzz
  • 623
  • 3
  • 11
1

Two solutions:

  1. Add your subdirectory to your library path (click on Edit next to ActionScript settings in the property panel and then on the first tab just add your directory)
  2. In your class file just change the package to nameofthesubdirectory
Kodiak
  • 5,978
  • 17
  • 35