# BitmapData.hitTest()

**URL:** https://forum.kirupa.com/t/bitmapdata-hittest/292674
**Category:** programming
**Created:** [July 17, 2009, 11:52am UTC](https://forum.kirupa.com/t/bitmapdata-hittest/292674 "2009-07-17T11:52:05Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![wkt](https://avatars.discourse-cdn.com/v4/letter/w/ed655f/32.png) [@wkt](https://forum.kirupa.com/u/wkt)
#### Post date: [July 17, 2009, 11:52am UTC](https://forum.kirupa.com/t/bitmapdata-hittest/292674/1 "2009-07-17T11:52:05Z")

</div>

Hi there

[[COLOR=#800080]http://www.kirupa.com/forum/showpost.php?p=1922772&postcount=4[/COLOR]](http://www.kirupa.com/forum/showpost.php?p=1922772&postcount=4)

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.

```auto

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.
