bitmapData - setPixels / setVector difficulties

Hi folks - my first question. I’m trying to get my head round bitmapData and everything you can do with it. I’m using **pure AS3 **at the moment

I’ve been playing with some Perlin noise examples - worked ok - and tried writing another image (png) onto the bitmapdata.

The new image is EMBEDed in the as3 code:


[Embed(source='icon.png')]
private var ImageClass:Class;
private var img:Bitmap = new ImageClass();

I write the perlin noise to the BitmapData thus:


var bmd:BitmapData = new BitmapData(200, 200, true, 0x00000000);
bmd.perlinNoise(baseX, baseY, octaves, seed, stitch, fractal, channels, grayscale, offsets);
var bm:Bitmap = new Bitmap(bmd);

Then drawing the image on like this, works:


bm.bitmapData.draw(img.bitmapData);

But using setPixels or setVector run into problems (“end of file encountered” for setPixels or “out of range” for setVector). The code:


var rectangle:Rectangle = new Rectangle(0, 0, img.height, img.width);
var v:Vector.<uint> = img.bitmapData.getVector(rectangle);

bm.bitmapData.setVector(rectangle, v);

can anyone help? Thanks in advance
Henry