Wednesday, March 17, 2010

Actionscript 3 load BitmapData

Hi all!
I've found this intersting page explain how to load an image (for example a PNG) into a BitmapData class (useful with Flashpunk too), i report here so anyone waste time anymore:


package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;

[SWF(width = "800", height = "600")]
public class Main extends Sprite
{

[Embed(source="test.png")]
public var MyEmbed:Class;

public function Main()
{
var bit:BitmapData = getBitmapData();
}

public function getBitmapData():BitmapData
{
var image:Bitmap = new MyEmbed();
return image.bitmapData;
}
}
}


You need a test.png, obviously :D you can found a little Flashdevelop working example here.

No comments:

Post a Comment