Wednesday, February 06, 2008

embed bitmap in haxe




I wanted to use swfmill to generate a library of images and then display them in haXe. Krzysztof Rozalski came up with a solution on the haXe mailing list. Thanks Christopher, this was really helpful!

The code I wrote ended up looking like:

swflib.xml:


<?xml version="1.0" encoding="iso-8859-1" ?>
<movie version="9" width="320" height="240" framerate="12">
<background color="#ffffff"/>
<frame>
<library>
<bitmap id="MyBitmapData" name="MyBitmapData" import="library/play.png" />
</library>
</frame>
</movie>


And the haXe code:


import flash.display.BitmapData;

class MyBitmapData extends BitmapData
{
public function new()
{
super(0,0);
}
}

class SwfImport
{

static function main ()
{
var bitmapData:BitmapData;
bitmapData = new MyBitmapData();
flash.Lib.current.addChild( new flash.display.Bitmap(
bitmapData, flash.display.PixelSnapping.AUTO, true ) );
}
}


This is all compiled with:


-main SwfImport
-swf ../swfimport.swf
-swf-version 9
-swf-lib swflib.swf