# Event hitTest

**URL:** <https://forum.kirupa.com/t/event-hittest/281249>\
**Category:** flash\
**Created:** [February 6, 2009, 3:26pm UTC](https://forum.kirupa.com/t/event-hittest/281249 "2009-02-06T15:26:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trickeyd](https://avatars.discourse-cdn.com/v4/letter/t/f17d59/32.png) [@trickeyd](https://forum.kirupa.com/u/trickeyd)\
**Post date:** [February 6, 2009, 3:26pm UTC](https://forum.kirupa.com/t/event-hittest/281249/1 "2009-02-06T15:26:00Z")

</div>

Hi everyone.

I am creating a system with creatures that need to know when they hit each-other. At the moment I am using the following loop for each creature in each frame:

```auto

if (!_pregnant)
			{
				for(var i:Number = 0;i < Root.maleArray.length; i++)
				{
					if (this.hitTestObject(Root.maleArray*))
					{
						_newDNA = (Root.maleArray*._dna + _dna)/2;
						_pregnant = true;
					}
				}
			}

```

As these creatures breed there is quite a few by the end so the app slows greatly.

Is there a way I can listen for a collision of any two elements before I trigger the loop?

eg:

```auto

addEventListener(Event.hitTestObject, collision);

function collision(e:Event):void
{

if (!_pregnant)
			{
				for(var i:Number = 0;i < Root.maleArray.length; i++)
				{
					if (this.hitTestObject(Root.maleArray*))
					{
						_newDNA = (Root.maleArray*._dna + _dna)/2;
						_pregnant = true;
					}
				}
			}
}

```

Thank you!🔗
