0

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

flinthart
  • 534
  • 1
  • 4
  • 14

1 Answers1

0

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.

stroncium
  • 1,430
  • 9
  • 8
  • Hi - the swf file I loaded was created using openfl as well - just images in the assets - and the main class. I'm not sure what I need to check in order to find why the images are being defined by the DefineBitsJPEG2 tag? I'll have another look over it and see if I can identify the problem. – flinthart May 28 '14 at 15:09
  • Well, that seems like an interesting problem now anf probably openfl bug(subtle). If you won't be able to solve it, you could hand to me a mininmal reproduction case, and I'll look into it. – stroncium Jun 02 '14 at 14:57