Hi there


This is for BitmapData hittesting 2 objects. The restriction is that it does not work when the registration point is not at the top left corner of the object. So I made some changes, hoping to make it work like this.

MovieClip.prototype.pixelHitTest = function(mc:MovieClip, threshold:Number):Boolean  {
 threshold = threshold ? treshold : 1;
 var xOffset:Number = this.getBounds(this).x; 
 var yOffset:Number = this.getBounds(this).y; 
 var xOffsetMC:Number = this.getBounds(mc).x; 
 var yOffsetMC:Number = this.getBounds(mc).y;
 var thisBitmap:BitmapData = new BitmapData(this.width, this.height, true, 0);
 thisBitmap.draw(this, new Matrix(1, 0, 0, 1, - xOffset, -yOffset)); 
 var mcBitmap:BitmapData = new BitmapData(mc.width, mc.height, true, 0);
 mcBitmap.draw(mc, new Matrix(1, 0, 0, 1, - xOffsetMC, -yOffsetMC));
 if (thisBitmap.hitTest(new Point(this.x+xOffset, this.y+yOffset), threshold, mcBitmap, new Point(mc.x+xOffsetMC, mc.y+yOffsetMC), threshold)) {
  return true;
 return false;

I just modified the original according to the instructions on another website. However, it doesn’t quite work. Where’s the problem?

Thanks in advance.