# Hit test problem

**URL:** <https://forum.kirupa.com/t/hit-test-problem/186752>\
**Category:** Uncategorized\
**Created:** [April 24, 2006, 11:34am UTC](https://forum.kirupa.com/t/hit-test-problem/186752 "2006-04-24T11:34:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcem](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@dcem](https://forum.kirupa.com/u/dcem)\
**Post date:** [April 24, 2006, 11:34am UTC](https://forum.kirupa.com/t/hit-test-problem/186752/1 "2006-04-24T11:34:04Z")

</div>

I am having trouble getting the collision detection working for my portfolio site. I want it so that when one square is over another it moves to another location. This is because the squares are going to be buttons and i cant have buttons covering each other.

help would really be appreciated, i am going crazy trying to figure out what i am doing wrong! :puzzle:

here is a link to the files, the hit test function is in Square.as line 78.  
[http://www.dcem.net/dcemprob.zip](http://www.dcem.net/dcemprob.zip)

Thanks!

Dave

---

<div class="post-metadata">

**Author:** ![dcem](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@dcem](https://forum.kirupa.com/u/dcem)\
**Post date:** [April 25, 2006, 1:00am UTC](https://forum.kirupa.com/t/hit-test-problem/186752/2 "2006-04-25T01:00:23Z")

</div>

Here is the function itself that is in the external class file Square.as:

function hitTester(){  
tempA = this.  
//array filled with the names of each  
numSquare = \_rootALL.SquareNames.length;

---

<div class="post-metadata">

**Author:** ![dcem](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@dcem](https://forum.kirupa.com/u/dcem)\
**Post date:** [April 25, 2006, 1:00am UTC](https://forum.kirupa.com/t/hit-test-problem/186752/3 "2006-04-25T01:00:23Z")

</div>

Here is the function itself that is in the external class file Square.as:

function hitTester(){  
tempA = this.  
//array filled with the names of each  
numSquare = \_rootALL.SquareNames.length;

---

<div class="post-metadata">

**Author:** ![dcem](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@dcem](https://forum.kirupa.com/u/dcem)\
**Post date:** [April 25, 2006, 1:04am UTC](https://forum.kirupa.com/t/hit-test-problem/186752/4 "2006-04-25T01:04:01Z")

</div>

Here is the function itself that is in the external class file Square.as:

function hitTester(){  
tempA = this.  
//array filled with the names of each object instance to be tested for hit  
numSquare = \_rootALL.SquareNames.length;  
for(i=0; i\<numSquare; i++){  
if(i != ArrayNo){  
tempB = root.ALL.SquareNames[i[;  
if(tempA.hitTest(tempB)){  
//function to move offending square  
moveSquare  
}  
}  
}

now it runs the for loop and gets the names of each of the squares but doesnt seem to register when on hits another. HEEEEELP!
