# HitTest through function

**URL:** <https://forum.kirupa.com/t/hittest-through-function/113271>\
**Category:** Uncategorized\
**Created:** [June 16, 2004, 1:50pm UTC](https://forum.kirupa.com/t/hittest-through-function/113271 "2004-06-16T13:50:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghjr](https://avatars.discourse-cdn.com/v4/letter/g/dec6dc/32.png) [@ghjr](https://forum.kirupa.com/u/ghjr)\
**Post date:** [June 16, 2004, 1:50pm UTC](https://forum.kirupa.com/t/hittest-through-function/113271/1 "2004-06-16T13:50:09Z")

</div>

I’m having troubles activating the **HitTest** , passing the objects name as a parameter through a global function. Let’s say there is the following function on the main timeline:

```auto

_global.fallIntoBasket = function (fallingObject) {

	if (_root[fallingObject].hitTest(_x, _root.basket_mc._y+(_root.basket_mc._height/2)-7, true)) {
  		trace ("teste");
		_root[fallingObject]._alpha=0;
	}

}

```

I then call this function passing the this.\_name of the object as a parameter in a **onClipEvent (EnterFrame)** on each of the falling Objects action box. The whole detection thing doesn’t work though… but if I place the hitTest code on each of the object, and change the **\_root[fallingObject]** to **this** it works.

Any ideas? Can I not pass hitTest through a function? Thanks!!

ghjr

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 3:18pm UTC](https://forum.kirupa.com/t/hittest-through-function/113271/2 "2004-06-16T15:18:56Z")

</div>

If I replace the if statement with

```auto
if (_root[fallingObject].hitTest(_root._xmouse, _root._ymouse)) {

```

it works:)  
So…

scotty(-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 4:09pm UTC](https://forum.kirupa.com/t/hittest-through-function/113271/3 "2004-06-16T16:09:54Z")

</div>

> [@scotty](#):
>
> If I replace the if statement with
> 
> ```auto
> if (_root[fallingObject].hitTest(_root._xmouse, _root._ymouse)) {
> 
> ```
> 
> it works:)  
> So…
> 
> scotty(-:

Yuppers!! That Y equation was messing it up, gonna make some changes!! Thanks scotty.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 16, 2004, 6:23pm UTC](https://forum.kirupa.com/t/hittest-through-function/113271/4 "2004-06-16T18:23:14Z")

</div>

You’re welcome, ghjr:thumb:
