简体   繁体   English

OpenFL加载外部SWF并获取资产

[英]OpenFL Load External SWF and get the assets

I'm trying to load a swf file into another swf and then extract the assets from the first. 我正在尝试将一个SWF文件加载到另一个SWF文件中,然后从第一个文件中提取资产。

Both swf files are being created using OpenFL (compiled in FlashDevelop). 这两个swf文件都是使用OpenFL(在FlashDevelop中编译)创建的。

I can load the external swf easily and convert it to a SWF object (haxelib swf library). 我可以轻松加载外部swf并将其转换为SWF对象(haxelib swf库)。

But then I can't extract the images from the SWF? 但是,我不能从SWF中提取图像吗?

var req:URLRequest = new URLRequest('TestSwf.swf');
var loader:URLLoader = new URLLoader(); 
loader.addEventListener(Event.COMPLETE, function(e:Event) 
{
    var byteArray:ByteArray = cast(e.target, URLLoader).data;
    trace(['ByteArray length', byteArray.length]);  
    trace(byteArray.length);

    var slide_swf:SWF = new SWF (byteArray);
    trace(slide_swf.hasSymbol("__ASSET__assets_img_0002_png"));
    var sym:Dynamic = slide_swf.data.getCharacter(slide_swf.symbols.get("__ASSET__assets_img_0002_png"));
    trace(sym);

    var bmpd:BitmapData = slide_swf.getBitmapData("__ASSET__assets_img_0002_png");
    trace(bmpd);
    var bmp:Bitmap = new Bitmap(bmpd);
    trace(bmp.width);
    this.addChild(bmp);
});
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(req);

The output from running this is : 运行此命令的输出是:

Main.hx:42: [ByteArray length,738913]
Main.hx:43: 738913
Main.hx:46: true
Main.hx:48: [00:DefineBitsJPEG2] ID: 1002, Type: PNG, BitmapLength: 531065
Main.hx:50: null
Main.hx:57: 0

You can see that the sym type is of DefineBitsJPEG2 which SWF can't convert into a Bitmap. 您会看到sym类型是DefineBitsJPEG2,SWF无法将其转换为位图。

So how can I extract the assets from the SWF file? 那么,如何从SWF文件中提取资产? Or am I going about this in completely the wrong way?? 还是我完全以错误的方式去做?

Any help would be greatly appreciated!! 任何帮助将不胜感激!!

I'm not sure how you did that, but you put PNG in DefineBitsJPEG tag, which makes no sense, since there are DefineBitsLossless and DefineBitsLossless2 tags for that. 我不确定您是如何做到的,但是您将PNG放在了DefineBitsJPEG标记中,这没有任何意义,因为有针对此的DefineBitsLossless和DefineBitsLossless2标记。 I can't be sure if it is invalid in every situation in flash, but I'm almost completely sure that is the reason of your problem. 我无法确定它在Flash中的每种情况下是否都是无效的,但是我几乎完全可以确定,这就是您遇到问题的原因。

There is a slight chance that it is a bug in openfl implementation which makes DefineBitsJPEG out of DefineBitsLossless, but I'd suggest you to try to fix your side first and check openfl sources only if it doesn't work out and you're completely sure you have the right tag. 很有可能这是openfl实现中的一个错误,这使DefineBitsJPEG脱离了DefineBitsLossless,但是我建议您先尝试修复问题,并仅在无法解决且完全确定openfl源的情况下检查它确保您有正确的标签。

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

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