强制编译时链接 SWC 中的所有类
我正在使用 Flash CS4 制作一款具有十几个声音和几首音乐曲目的游戏。为了减少发布/编译时间,我已将声音和音乐移至(外部)SWC,该 SWC 位于项目的“库路径”中。这可行,但有一个警告...
直到我将资产外部化之前,我一直通过使用 获取它们的类来动态实例化嵌入声音的
。Sound
对象>getDefinitionByName
// something like...
var soundSubClass:Class = Class(getDefinitionByName(soundClassName));
var mySound:Sound = new soundSubClass();
但现在它们位于外部 SWC 中,我需要对这些类有“具体”引用才能像这样加载它们,否则它们不会包含在已发布的 SWF 中,并且在 getDefinitionByName
尝试获取不存在的类。
那么,我的问题:在Flash Professional CS4中,有没有办法强制包含库的资源,无论它们是否静态链接?
FlashDevelop有一个编译器选项“SWC Include Libraries”,这正是我想要的,并且与“SWC Libraries”选项不同。 “SWC 包含库”选项的描述是“将 SWC 文件内的所有类链接到生成的应用程序 SWF 文件,无论是否使用它们”。
(此外,对我来说很重要的是,所有资源都包含在一个已编译的 SWF 中。运行时链接并不是我所追求的。)
Using Flash CS4, I am making a game that has a dozen or so sounds and a couple of music tracks. To cut down on publish/compile time, I have moved the sounds and music into an (external) SWC, which is located in a "Library Path" for the project. This works, but with a caveat...
Until before I externalised the assets, I had been dynamically instantiating the Sound
objects of the embedded sound by getting their classes with getDefinitionByName
.
// something like...
var soundSubClass:Class = Class(getDefinitionByName(soundClassName));
var mySound:Sound = new soundSubClass();
But now that they're located in an external SWC, I need to have "concrete" references to the classes in order to load them like this, otherwise they are not included in the published SWF, and there is a runtime error when getDefinitionByName
tries to get a class that doesn't exist.
So, my question: in Flash Professional CS4, is there any way to force a library's assets to be included, regardless of whether they are statically linked?
FlashDevelop has a compiler option "SWC Include Libraries", which is exactly what I want, and is distinct from the "SWC Libraries" option. The description of the "SWC Include Libraries" option is "Links all classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used."
(Also, it's important to me that all the assets are contained within the one compiled SWF. Linking at runtime isn't what I'm after.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 flex 中,只要您有权访问编译器选项,您就可以使用: -include YourClass 来强制从 swc 链接该类,即使它没有从主 swf 引用。
但我不知道你是否可以更改 flash cs4 的编译器选项...
in flex, and whenever you have access to compiler options, you can use: -include YourClass to force the linking of the class from swc even if its not referenced from the main swf.
but i dont know if you can change compiler options from flash cs4...
您可以在 ActionScript 属性中提供 asset.swc 文件的路径,该文件应该在运行时运行并加载资源。
You can supply the path of your assets.swc file, in ActionScript Properties, and that should work and load assets at runtime.
我可能遗漏了一些东西,但这不是使用 -include-libraries 而不是编译器的库路径选项的情况吗,这就是 adobe 文档关于该选项的说法
将 SWC 文件中的所有类链接到生成的应用程序 SWF文件,无论是否使用它们。
将此选项与仅包含编译时引用的类的库路径选项进行对比。
Adobe 文档
我对这一切都很陌生,所以当你用火焰射死我:)
I am probably missing something but isn't it a case of using -include-libraries rather than library-path option of the compiler, this is what the adobe doc says about the option
Links all classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used.
Contrast this option with the library-path option that includes only those classes that are referenced at compile time.
Adobe Documentation
I am new to all this so be gentle when you shoot me down in flames :)
默认情况下,在 Flash CS4/CS5 中,无法将每个类引入并嵌入到 SWC 中,但您可以使用以下方法来实现此操作:
FlashDevelop
正如您所知,该程序的项目属性具有编译器区分以下选项的选项:
第二个选项“SWC Include Libraries”可能很有用,因为如果您只是将 FLA 按原样编译为 SWC,然后将该 SWC 和其他 SWC 作为 SWC Include Libraries 放入 FlashDevelop,它应该将它们编译/合并为一个SWF 将按照您想要的方式工作。
FlashDevelop 还可以简单地帮助您在 SWC 中构建硬编码的类列表,因为如果您将 SWC 作为 SWC 库链接,它将显示在项目资源管理器中,并且您可以看到其中所有类的列表。 SWC。您还可以右键单击每个类并选择“插入文档”,它将插入完整的类名。如果你这样做了,然后按分号回车键,你将获得第一类参考文献。将鼠标悬停在项目设置中的类列表上,并对列表中的每个类重复此操作。对数百个类执行此操作只需几分钟,这使得创建此类列表变得更加容易。如果这个东西能让你一次插入多个,那就更快了,但事实似乎并非如此。
您唯一的其他选择是运行时共享库 (RSL),您说您出于某种原因对此不感兴趣。单独加载文件确实没什么大不了的,但前提是您正确处理加载过程和可能发生的任何错误。它会给您的项目增加一些复杂性,并且可能需要一些额外的思考,但我会认真考虑将其作为一种选择。请参阅 www.senulous.com/flash/tutorials 中的“应用程序域继承”部分/contentdomains/?page=2 了解更多信息。
There's no way to pull in and embed every class in an SWC by default in Flash CS4/CS5, but you may be able to do this with:
FlashDevelop
As you already know, this program's project properties has compiler options that differentiate between:
That second option "SWC Include Libraries" could be useful, because if you simply compile your FLA as-is into a SWC, then put that SWC and your other SWC into FlashDevelop as SWC Include Libraries, it should compile/merge them into a single SWF that will work like you want.
FlashDevelop could also simply help you build a hard-coded list of Classes in an SWC, because if you link in the SWC as a SWC Library, it will show up in the project explorer, and you can see a list of all the classes in the SWC. You can also right click each class and choose "Insert Into Document", and it will insert the full class name. If you do that, then press semi-colon enter, you will have your first class reference. Keep your mouse over the class list in the project settings and repeat this for every class in the list. It only takes a few minutes to do this for hundreds of classes, which makes creating such a list easier. It would be even faster if the thing would let you insert more than one at once, but it doesn't seem to.
Your only other option, which you said you weren't interested in for no given reason, is Runtime Shared Libraries (RSLs). It's really not that big a deal to load the file in separately, but only if you properly handle the load process and any errors that might occur. It will add some complexity to your project, and may require some extra thought, but I'd seriously consider it as an option. See the "Application Domain Inheritance" section at www.senocular.com/flash/tutorials/contentdomains/?page=2 for more information.
不幸的是,我不这么认为。我希望这在 CS5 中得到解决,但我不会打赌......
当前(加重)标准是在 SWC 中有一个清单类,它引用库其余部分中的所有根类:
然后,在某个地方在你的主 .fla...
Unfortunately, I don't think so. I hope this is fixed in CS5, but I wouldn't bet on it...
The current (aggravating) standard is to have a manifest class in your SWC that references all the root classes in the rest of the library:
Then, somewhere in your main .fla...