Wwwebber's Blog

Loading External BitmapData into Vector of Type BitmapData

Posted in actionscript 3, bitmapdata, flash player 10, vector by wwwebber on November 22, 2008

I’m working on a math game that requires many external images to be loaded into Actionscript 3’s new Vector class (typed array) . It took me a bit of experimenting to determine how to properly load external images into a Vector of type BitmapData. Before the new the typed arrays of our new Vector class, I didn’t have to worry about the type of the data that I was storing (arrays can handle any type)…now, it’s a whole new ball game

. In the end, you just cast the content of the loader object to a Bitmap then access that Bitmap’s “.bitmapData” property…see a simplified version of my code below.

//Here’s my BitmapData Vector
var explosionVec:Vector. = new Vector.();

//load external png
var _loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded,false,0, true);
_loader.load( new URLRequest(“bath/To/Image/explosion.png”));

function loaded(e:Event):void{
//cast content to bitmap
var bmp:Bitmap = Bitmap(_loader.content);
//store the bitmapData from the Bitmap!
explosionVec[0] = bmp.bitmapData;



Comments Off on Loading External BitmapData into Vector of Type BitmapData