简体   繁体   English

使用Flex Builder 3将SWF包中的ActionScript类编译为swf

[英]Compile an ActionScript class that is in a package to a swf using Flex Builder 3

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. 如何在Flex Builder 3 Pro中配置ActionScript项目 ,以便可以将作为包的一部分的ActionScript类编译为swf。 For example, the class that I want to compile to swf is: 例如,我要编译为swf的类为:

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

    }
}

Take a directory structure like the following: 采用如下目录结构:

RootASProject RootASProject
-RootASProject.mxml -RootASProject.mxml
-subASProject1 -subASProject1
--subSubASProject1a --subSubASProject1a
---IASModule.as ---IASModule.as
---ASModule.as ---ASModule.as
---ASModule.swf --- ASModule.swf
--subSubASProject2 --subSubASProject2
-utils -实用程序
--ITool.as --iTool.as
--Tool.as -工具
--Tool.fla --Tool.fla
--Tool.swf --Tool.swf

RootASProject is being produced by one developer, subASProject1 and subSubASProject1a by another developer, utils.Tool by yet another person. RootASProject由一个开发人员subASProject1和subSubASProject1a由另一开发人员utils.Tool生产。 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". 例如,Tool.swf包含/定义“ utils.Tool”而不是“ Tool”。

Developing with just the Flash IDE, this directory structure is not a problem. 仅使用Flash IDE进行开发,此目录结构就不成问题。 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. 我们创建一个Tool.fla并将utils.Tool分配为其文档类,然后在Flash IDE的发布设置中,将类路径设置为不是当前目录(。),而是RootASProject目录。 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'. 如果将其设置为当前目录,则错误将是:在源路径中找到的文件必须具有与定义的包“ utils”相同的包结构“”。 Tool Tool.as. 工具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. 我们熟悉此错误消息,因此我知道默认情况下,Flex IDE默认在当前目录中查找子文件夹utils,以匹配打包的类。

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. 在Flex IDE中,我可以将utils父项RootASProject添加为附加的源路径,但是我不知道如何阻止flex首先在当前目录中查找。

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. 使用ant构建文件,我可以将源路径设置为RootASProject,并且mxmlc能够很好地构建utils / Tool.swf。 Apparently, it uses just the source paths passed to it, and does not automatically look for utils in the current directory. 显然,它仅使用传递给它的源路径,并且不会自动在当前目录中查找utils。

I know the problem is resolved by using Flash or Ant. 我知道可以通过使用Flash或Ant解决问题。 Ant is even preferred for larger and automatic builds; 对于大型的自动构建,甚至首选Ant。 however, during rapid debugging I'd really enjoy being able to stay within the Flex IDE to step through code using its debugger. 但是,在快速调试期间,我真的很喜欢能够留在Flex IDE中,以使用其调试器逐步调试代码。

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. 简单的解决方案是创建一个名为“ utils”的文件夹,然后将Tool.as移到该文件夹​​中。

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. 假设您的项目是一个ActionScript项目,并且以上类被标记为您的Application,那么它应该可以正常工作。

如果您使用的是Flex Builder 3或更高版本,只需通过转到文件>新建> ActionScript项目来创建一个新的ActionScript项目,然后将ITool.as文件分配为其中的主要Application文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM