# Hit object then remove from array

**URL:** <https://forum.kirupa.com/t/hit-object-then-remove-from-array/309225>\
**Category:** flash\
**Created:** [May 10, 2010, 1:47pm UTC](https://forum.kirupa.com/t/hit-object-then-remove-from-array/309225 "2010-05-10T13:47:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JWH89](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@JWH89](https://forum.kirupa.com/u/JWH89)\
**Post date:** [May 10, 2010, 1:47pm UTC](https://forum.kirupa.com/t/hit-object-then-remove-from-array/309225/1 "2010-05-10T13:47:08Z")

</div>

Hello,

Having a problem with my game. I am running a hittest to see if my avatar hits a food movie clip. When it does I want to remove the child that has been hit. I have put all the food movieclips into an array called prey.

Currently what I have when my avatar hits a food it removes the whole array but I only want the food movie clip which has been hit to be removed.

Any ideas how I can do this?

Thanks in advance

```auto

var newFood:Food=new Food(650,randomyFood);
prey.push(newFood);
addChild(newFood);

var foodHasBeenHit:Boolean=false;
			for each (var food:Food in prey) {
				food.moveABit();
				if (PixelPerfectCollisionDetection.isColliding(avatar,food,this,true)) {
					foodHasBeenHit=true;
				}
			}
			
			for(var i:int = 0; i<prey.length; i++)
			if (foodHasBeenHit){
			
				gameScore.addToValue(20);
				
				prey*.parent.removeChild(prey*);
				prey.splice(i, 1);
			}

```
