# Shoot Bullet Array

**URL:** <https://forum.kirupa.com/t/shoot-bullet-array/276461>\
**Category:** flash\
**Created:** [November 27, 2008, 8:35pm UTC](https://forum.kirupa.com/t/shoot-bullet-array/276461 "2008-11-27T20:35:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryrocks](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@ryrocks](https://forum.kirupa.com/u/ryrocks)\
**Post date:** [November 27, 2008, 8:35pm UTC](https://forum.kirupa.com/t/shoot-bullet-array/276461/1 "2008-11-27T20:35:00Z")

</div>

Hey,  
I’m trying to fix my character shooting function/hit test. If I shoot one bullet at an enemy mc then the hit test occurs and the enemy plays the “dead” animation. However if I fire multiple bullets then the hit test wont occur until the last bullet hits. I guess every time I fire a bullet it creates a new instance of the class and any previous instances can’t be called on using bulletVar.

I presume my best bet would be to put each bullet into an array? I’ve no idea how to code this though, any help would be much appreciated!

Here’s the code:

var bulletVar:bullet = new bullet();

stage.addEventListener(KeyboardEvent.KEY\_DOWN, downDetect);  
function downDetect(event:KeyboardEvent):void  
{  
if(event.keyCode == Keyboard.SPACE)  
{  
bulletVar = new bullet();  
this.addChild(bulletVar);

```
	if(facingRight || rightDown)
	{
		bulletVar.x = (ball_mc.x + 253 );
		bulletVar.gotoAndPlay("shoot_right");
	}
	else if(facingLeft || leftDown)
	{
		bulletVar.x = (ball_mc.x + 203);
		bulletVar.gotoAndPlay("shoot_left");
	}
}

```

}

stage.addEventListener(Event.ENTER\_FRAME, hitEnemy);  
function hitEnemy(event:Event):void  
{  
if (bulletVar.hitTestObject(enemy\_mc))  
{  
enemy\_mc.gotoAndStop(“dead”);  
stage.removeEventListener(Event.ENTER\_FRAME, hitEnemy);  
this.removeChild(bulletVar);  
}  
}

Thanks  
Ryan
