views:

1127

answers:

2

How do I configure an ActionScript Project in Flex Builder 3 Pro so that I can compile an ActionScript class that is part of a package into a swf. For example, the class that I want to compile to swf is:

package utils {
    import flash.display.Sprite;
    public class Tool extends Sprite {
        public function Tool() {

    }
}

Take a directory structure like the following:

RootASProject
-RootASProject.mxml
-subASProject1
--subSubASProject1a
---IASModule.as
---ASModule.as
---ASModule.swf
--subSubASProject2
-utils
--ITool.as
--Tool.as
--Tool.fla
--Tool.swf

RootASProject is being produced by one developer, subASProject1 and subSubASProject1a by another developer, utils.Tool by yet another person. This directory structure enables each person to independently build modules and other resources, and quickly test the entire product. It is also important to note that these resources are loaded at runtime. So, class definitions must be fully qualified. For example, Tool.swf contains/defines "utils.Tool" not "Tool".

Developing with just the Flash IDE, this directory structure is not a problem. We create a Tool.fla and assign utils.Tool as it's Document Class then in the Flash IDE's Publish Setting, we set the class path to be NOT the current directory (.), but instead the RootASProject directory. If it were set to the current directory, the error would be: A file found in a source-path must have the same package structure '', as the definition's package, 'utils'. Tool Tool.as. We're familiar with this error message and so I recognize that the Flex IDE is by default looking in the current directory for a subfolder, utils, to match the packaged class.

In the Flex IDE, I can add the utils parent, RootASProject, as an additional source path, but I do not know how to stop flex from looking in the current directory first.

Using an ant build file, I can set the source path to RootASProject and the mxmlc is able to build utils/Tool.swf just fine. Apparently, it uses just the source paths passed to it, and does not automatically look for utils in the current directory.

I know the problem is resolved by using Flash or Ant. Ant is even preferred for larger and automatic builds; however, during rapid debugging I'd really enjoy being able to stay within the Flex IDE to step through code using its debugger.

A: 

Your compilation error is unrelated to its use as a document class. Your directory structure needs to match your package in your clas. The simple solution is to create a folder called "utils" and move your Tool.as into that folder.

What you refer to as a "document" class is the base class of the exported symbol. Assuming your project is an ActionScript project and the above class is marked as your Application, then it should work as expected.

Richard Szalay
+1  A: 

If you are using Flex Builder 3 or better, simply create a new ActionScript project by going File > New > ActionScript Project and assign your ITool.as file as the main Application file in it.

Q-rius