使用 Flex Builder 3 将包中的 ActionScript 类编译为 swf
如何在 Flex Builder 3 Pro 中配置 ActionScript 项目,以便将属于包一部分的 ActionScript 类编译为 swf。 例如,我要编译为 swf 的类是:
package utils {
import flash.display.Sprite;
public class Tool extends Sprite {
public function Tool() {
}
}
采用如下目录结构:
RootASProject
-RootASProject.mxml
-subASProject1
--subSubASProject1a
---IASModule.as
---ASModule.as
---ASModule.swf
--subSubASProject2
-utils
--ITool.as
--工具.as
--工具.fla
--Tool.swf
RootASProject 由一位开发人员生成,subASProject1 和 subSubASProject1a 由另一位开发人员生成,utils.Tool 由另一位开发人员生成。 这种目录结构使得每个人都可以独立构建模块和其他资源,并快速测试整个产品。 还需要注意的是,这些资源是在运行时加载的。 因此,类定义必须是完全限定的。 例如,Tool.swf 包含/定义“utils.Tool”而不是“Tool”。
仅使用 Flash IDE 进行开发,这种目录结构不是问题。 我们创建一个 Tool.fla 并分配 utils.Tool 作为它的文档类,然后在 Flash IDE 的发布设置中,我们将类路径设置为NOT当前目录 (.),而是 RootASProject 目录。 如果将其设置为当前目录,则错误将是:在源路径中找到的文件必须具有与定义的包“utils”相同的包结构“”。 工具 Tool.as。 我们熟悉此错误消息,因此我认识到 Flex IDE 默认情况下会在当前目录中查找子文件夹 utils,以匹配打包的类。
在 Flex IDE 中,我可以添加 utils 父级 RootASProject 作为附加源路径,但我不知道如何阻止 Flex 首先查找当前目录。
使用 ant 构建文件,我可以将源路径设置为 RootASProject,并且 mxmlc 能够很好地构建 utils/Tool.swf。 显然,它只使用传递给它的源路径,并且不会自动在当前目录中查找 utils。
我知道这个问题可以通过使用Flash或Ant解决。 Ant 甚至更适合大型自动构建; 然而,在快速调试期间,我真的很喜欢能够留在 Flex IDE 中使用其调试器单步执行代码。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的编译错误与其用作文档类无关。 您的目录结构需要与类中的包匹配。 简单的解决方案是创建一个名为“utils”的文件夹并将 Tool.as 移动到该文件夹中。
您所说的“文档”类是导出符号的基类。 假设您的项目是一个 ActionScript 项目,并且上面的类被标记为您的应用程序,那么它应该按预期工作。
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.
如果您使用的是 Flex Builder 3 或更高版本,只需通过转到“文件”>“创建一个新的 ActionScript 项目”即可。 新的> ActionScript 项目并将 ITool.as 文件指定为其中的主应用程序文件。
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.