0
votes

I'm trying to load a swf file into another swf and then extract the assets from the first.

Both swf files are being created using OpenFL (compiled in FlashDevelop).

I can load the external swf easily and convert it to a SWF object (haxelib swf library).

But then I can't extract the images from the 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.

So how can I extract the assets from the SWF file? Or am I going about this in completely the wrong way??

Any help would be greatly appreciated!!

1
You show us wrong logs. There is 4 traces in your source code and 6 lines in logs.stroncium
Updated the code to add in the extra traces. Thanks for spotting that!flinthart

1 Answers

0
votes

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. 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.

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.