使用 MXMLC 从命令行编译动作脚本
我有一个很小的动作脚本“项目”,由两个文件组成,分别称为 foo.as 和 bar.as。 由于我不会详细说明的原因,我真的很想从命令行构建 .SWF,而不设置任何类型的正式项目。 我曾经使用过的每个编译器都允许您执行此操作,但我一生都无法弄清楚如何强制 MXMLC 编译这两个文件并将它们链接到 SWF。
天真地,我尝试了
MXMLC foo.as bar.as
,但我被告知只允许一个源文件。
好吧,假设我分别编译这两个文件,我如何将它们链接在一起以获得最终的 SWF?
注意:我有两个文件而不是一个文件的唯一原因是每个文件只需要一个类。 我尝试将这两个类放入一个文件中,并将其中一个类设为 private
或 internal
,但这些想法都不起作用。 我会欣喜若狂地发现我可以将多个类放入一个文件中(只有一个类是公共的)。
I have a tiny actionscript "project" consisting of two files, call them foo.as and bar.as. For reasons I won't go into, I really really want to build the .SWF from the command line, without setting up a formal project of any kind. Every compiler I've ever used lets you do this, but for the life of me I can't figure out how to coerce MXMLC into compiling these two files and linking them into a SWF.
Naively, I try
MXMLC foo.as bar.as
but I'm informed that only one source file is allowed.
Ok, supposing I compiled these two files separately, how would I link them together to get the final SWF?
NOTE: The only reason I have two files instead of one is the requirement of only one class per file. I tried putting both classes in one file and making one of the classes private
or internal
but neither of these ideas worked. I would be ecstatic to find out I can put more than one class in a file (with only one being public).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是一个由两部分组成的问题,所以我将分别回答。
将两个类文件编译成一个 SWF
MXMLC 将自动编译它从您提供的入口点(您的主类)找到的所有类。 它从导入语句中查找类,以及完整的类路径定义。
这是一个非常好的使用 MXMLC 命令行编译 AS3 项目的指南。 这篇文章有点过时了,但信息仍然很好。 他详细介绍了使用命令行编译器时需要了解的内容,包括 MXMLC 选项、编写 BAT 脚本以及一些有关 AS3 的内容,如果您知道自己在做什么,则可以跳过这些内容。
一个文件中有多个类
AS3 允许每个文件有一个类,以及任意数量的“帮助”类。 它不像 Java 那样支持受保护的类和私有类。 辅助类仅在它们定义的文件中可见。
辅助类位于包声明之外(这对我来说有点奇怪)。 这是一个例子:
This is a two part question, so I will answer both separately.
Compiling two class files into one SWF
MXMLC will automagiclly compile all classes it finds from the entry point you give it (your main class). It finds classes from your import statements, and full class path definitions.
Here is a really good guide for using MXMLC command line to compile your AS3 projects. The article is a bit dated, but the information is still good. He goes into detail about the things you need to know when using the command line compiler, including the MXMLC options, writing BAT scripts, and a bit about AS3 that you can probably skip if you know what your doing.
Having more than one class in a file
AS3 allows you to have one class per file, plus as much "helper" classes as you like. It does not support protected and private classes like Java does. Helper classes are only visible in the file they are defined.
Helper classes sit outside the package declaration (which is a little weird to me). Here is an example:
如果主文件/类需要/使用其他文件的类,则其他文件也会被编译到 swf 中。
If the main file/class needs/uses the class of the other file, the other file will also be compiled into the swf.
正如 Hippo 所说,编译器会自动将代码中使用的所有类编译到 SWF 中,默认情况下是递归的。
您还可以阅读 MXMLC 编译器具有的所有选项。
As Hippo says, the compiler will automatically compile into the SWF all the classes used through your code, it's recursive by default.
You can read also all the options the MXMLC compiler has.
如果您有兴趣自动化该过程,您还可以使用 Project Sprouts,其中包含的内容比您想象的要多得多要求 - 但确实使您能够从终端启动构建和测试运行。
If you're interested in automating that process, you can also use Project Sprouts which includes quite a bit more than you're asking for - but does give you the ability to kick off builds and test runs from the terminal.
如果您使用 grunt 作为任务管理器(针对 js),则可以使用此插件:
https://github.com/JamesMGreene/grunt-mxmlc
您设置配置选项,然后从命令行运行它:
If you're using grunt as a task manager (for js), you can use this plugin:
https://github.com/JamesMGreene/grunt-mxmlc
You set config options then run it from command line: