# Preventing Overlap on Hit Test

**URL:** https://forum.kirupa.com/t/preventing-overlap-on-hit-test/314968
**Category:** flash
**Created:** [October 13, 2010, 4:43pm UTC](https://forum.kirupa.com/t/preventing-overlap-on-hit-test/314968 "2010-10-13T16:43:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![CCG1993](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@CCG1993](https://forum.kirupa.com/u/CCG1993)
#### Post date: [October 13, 2010, 4:43pm UTC](https://forum.kirupa.com/t/preventing-overlap-on-hit-test/314968/1 "2010-10-13T16:43:24Z")

</div>

I have searched the web for a solution and found none.;(

I have two rectangles, one of which is draggable, and when **hitTestObject** occurs I want to prevent the overlap.

here is the code:

[FONT=Courier New]addEventListener(Event.ENTER\_FRAME, detectColl);

redSquare.addEventListener(MouseEvent.MOUSE\_DOWN, grabIt);  
redSquare.addEventListener(MouseEvent.MOUSE\_UP, dropIt);

function grabIt(event:MouseEvent):void {  
event.target.startDrag(false);  
}

function dropIt(event:MouseEvent):void {  
event.target.stopDrag();  
}

function detectColl(event:Event):void{

```
if (redSquare.hitTestObject(greenSquare)){
    [COLOR=Red]????[/COLOR]
    
}

```

}

[/FONT]
