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

Vectors! Typed arrays come to Actionscript 3

Posted in actionscript 3, flash player 10, vector example by wwwebber on November 20, 2008

Finally got my hands on CS4… one of the main new new perks of the Actionscript is the new Vector class (nothing to do with physics or vector graphics)…these are good old typed arrays in the style of C++ or Java.

Basics of the Syntax

//create a Vector and call it vec

var vec:Vector. <int> = new Vector.<int>();

now “vec” can only store ints! This allows for Type-safety in your code, and potentially performance gains.

to add an object to a vector just call .push()
//the next line adds the int ‘3’ to the vector

Much more info over at Senocular

Comments Off on Vectors! Typed arrays come to Actionscript 3