“链接”反对 Flex 中的 SWC
我正在尝试在 Flash/Flex 中制作一个非常简单的应用程序,该应用程序加载嵌入在 swf 本身中的图像,然后显示它。问题是我试图仅使用命令行(mxmlc 和 compc)来完成此操作,而不使用 @Embed,并且惨败。
我有一个非常简单的 Main.as :
package
{
import flash.display.*;
import flash.utils.*;
public class Main extends Sprite
{
public function Main () : void
{
var pDef:Class = getDefinitionByName("icon_big.png") as Class;
var _image:BitmapData = new pDef(0, 0);
var pSprite:Sprite = new Sprite();
pSprite.graphics.beginBitmapFill(_image);
pSprite.graphics.drawRect(0, 0, _image.width, _image.height);
pSprite.graphics.endFill();
addChild(pSprite);
}
}
}
如果我使用 Flash IDE 将 icon_big.png 添加到库中,则效果很好,但我不知道如何从命令行执行此操作。
我使用 compc 将 png 放入 swc 中:
compc --include-file icon_big.png icon_big.png -output assets.swc
这会生成一个 17 kb 的 asset.swf,比 icon_big.png 稍大。然后我尝试编译并链接 Main.as :
mxmlc -include-libraries+=assets.swc Main.as
这会生成一个 944 字节的 Main.swf,它显然不包含该资产,并且在运行时失败。
根据我发现的 mxmlc 文档,-include-libraries 应该与每个类链接,包括那些没有直接被代码引用的类(就像这里的情况,因为我从代码中获取类),并且毫不奇怪地在运行时失败。
请注意,相同的代码(或者更准确地说,相当等效的代码)在 Flash 项目中使用时可以工作 - 我不是要修复代码,而是要如何在命令行中执行 Flash 内部执行的任何操作。
我觉得我只是“没有得到”一些东西......有什么线索吗?
I'm trying to do a very simple app in Flash/Flex, that loads an image embedded in the swf itself and then shows it. The thing is I'm trying to do it using the command line only (mxmlc and compc) and without using @Embed, and failing miserably.
I have a very simple Main.as :
package
{
import flash.display.*;
import flash.utils.*;
public class Main extends Sprite
{
public function Main () : void
{
var pDef:Class = getDefinitionByName("icon_big.png") as Class;
var _image:BitmapData = new pDef(0, 0);
var pSprite:Sprite = new Sprite();
pSprite.graphics.beginBitmapFill(_image);
pSprite.graphics.drawRect(0, 0, _image.width, _image.height);
pSprite.graphics.endFill();
addChild(pSprite);
}
}
}
This works fine if I add icon_big.png to the Library using the Flash IDE, but I can't figure out how to do it from the command line.
I'm using compc to put the png inside a swc :
compc --include-file icon_big.png icon_big.png -output assets.swc
This generates a 17 kb assets.swf, slightly bigger than icon_big.png. Then I try to compile and link Main.as :
mxmlc -include-libraries+=assets.swc Main.as
This produces a 944 byte Main.swf, which clearly doesn't include the asset, and fails at runtime.
According to the mxmlc docs I found, -include-libraries should link with every class, including the ones not directly referenced by code (as is the case here, since I'm getting the class from code), and it unsurprisingly fails at runtime.
Note that this same code (or, more precisely, quite equivalent code) works when used within a Flash project - I'm not looking to fix the code, but how to do in the command line whatever Flash does internally.
I feel I'm just "not getting" something... any clues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我建议您从 swftools.org 下载 swftools。获得它们后,运行:
特别查看与值为 76 (0x4C) 的 SWF 标记相关的输出,称为
SYMBOLCLASS
。下面是一个名为 IntegerMemberBySlot 的导出类的示例:
您要从 asset.swf 中导出哪些符号?
I recommend you to download the swftools from swftools.org. Once you have them, run:
Take a look in particular at the output which relates to SWF tag with value 76 (0x4C), called
SYMBOLCLASS
.Here is an example of an exported class, named IntegerMemberBySlot:
What symbols are you exporting from your assets.swf?
您是否尝试过在使用 mxmlc 编译时将资产路径添加到源路径参数中?
-源路径./PATH/TO/ASSET
Have you tried adding the path of the assets to your source path parameter when compiling with mxmlc?
-source-path ./PATH/TO/ASSET
我认为您需要将 PNG 嵌入到一个类中,然后将该类编译到 SWC 中。我不认为你可以像你尝试的那样将 PNG 直接放入 SWC 中,但我可能是错的。
I think you need to embed the PNGs in a class, then compile that class into a SWC. I don't think you can put the PNGs directly into a SWC like you are trying to, but I could be wrong.
我有一个类似的情况(大型项目,带有图形资产的资源swc),无论我尝试什么,我都无法让Flex包含未直接从项目引用的资产和类(我想包含不同的皮肤,然后在运行时实例化正确的实例,具体取决于配置)。
最后,我找到了一种解决方法,即切换到运行时共享库 (RSL),而不是静态 swc。基本上,flex 会解绑 swc,并在运行时加载和链接包含的 swf,然后再运行应用程序本身。 swf 中的所有类和资源都以这种方式加载。可能不完全是你所追求的,但它对我有用。
I had a similar situation (large project, resource swc with graphic assets), and no matter what I tried, I could't get Flex to include assets and classes not directly referenced from the project (I wanted to include different skins, and then instantiate the proper one at runtime, depending on the configuration).
Finally, I found a workaround by instead of static swc liking, switching over to runtime shared libraries (RSLs). Basically, flex unbundles the swc, and loads and links the included swf in runtime, before running the application itself. All of the classes and assets in the swf are loaded this way. May not be exactly what you're after, but it works for me.