So I'm working on a flash game where I'm using bitmapdata to determine collision detection with terrain. The idea was to have two sets of terrain tiles, one with the actual terrain on top and a simpler one with only a few basic colors to determine collision. That way if the hero comes into contact with a certain color on the "heightmap" his movement can be halted, slowed, he can receive damage or be scaled up and down to show variance in height. In order ot do this I need to add a whole bunch of heightmap tiles by means of an array, same way as I add the tiles themselves. Doing this through bitmapdata is proving to be a lot more difficult than I expected and I keep running into errors when using the following code.
This is the Error that I get: TypeError: Error #1010: A term is undefined and has no properties.
As far as I can tell it's coming from the following bit of the code:
var bitmapData:BitmapData = new BitmapData(heightContainer.heightMapClip.width, heightContainer.heightMapClip.height);
But I have no idea what I'm doing wrong. Here's the code in its entirety, though I haven't gotten around to the array part yet, just need to get this to work first and I really want to try and figure out the rest for myself:
var heightMapClip = new heightMap();
heightContainer.addChild(heightMapClip);
var heightData:String;
var hContainer:Sprite = new Sprite();
heightMapClip.x=-200;
heightMapClip.y=-200;
var bitmapData:BitmapData = new BitmapData(heightContainer.heightMapClip.width, heightContainer.heightMapClip.height);
bitmapData.draw(heightContainer.heightMapClip);
var myHeightMap:Bitmap = new Bitmap(bitmapData);
heightContainer.addChildAt(hContainer,0);
heightContainer.hContainer.addChild(myHeightMap);
heightContainer.hContainer.addEventListener(Event.ENTER_FRAME, onClick);
function onClick(e:Event):void
{
var obj:Sprite = e.currentTarget as Sprite;
var myHeightMap:Bitmap = Bitmap(obj.getChildAt(0));
var pixelValue:uint = heightContainer.myHeightMap.bitmapData.getPixel(mouseX,mouseY);
heightData=pixelValue.toString(16);
if(heightData=="99ff00"){
trace("Collision Detected");
}
}
Any help on this would be greatly appreciated.