# Array hitTest Problems

Hello everyone

If anyone can help in the following problems then thank you in advance.

I am looking to fix the code I have created, I have an array of tanks (3) and bullets (3). In the code the bullet is supposed to fire from the tanks 2 out of 200 times on “enterFrame”. The bullets are placed in same rotation and position as the tank but they will not fire, where am I going wrong?!

The code is just the bit of the tanks and how they interact with the user (spaceship).

[AS]stage.addEventListener(“enterFrame”, updateXY);

function updateXY(evt:Event){

``````for(var i:int = 0; i &lt; myArray.length; i++) {
var dx:Number = spaceship.x - myArray*.x;
var dy:Number = spaceship.y - myArray*.y;

var angle:Number = Math.atan2(dy, dx);
var deg:Number = angle * (180 / Math.PI);

myArray*.rotation = deg;

}
``````

}

var myArrayBulletsSpeed:Number = 16;
var myArrayBulletsFired:Boolean = false;

var myArrayBulletsXspeed:Number;
var myArrayBulletsYspeed:Number;

stage.addEventListener(“enterFrame”, firemyArrayBullets);

function firemyArrayBullets(evt){

``````for(var i:int = 0; i &lt; myArray.length; i++) {
if("enterFrame" && myArrayBulletsFired == false){
if(Math.random() * 200 &lt; 10){
myArrayBulletsFire();
}

}
}
``````

}

function myArrayBulletsFire(){

``````for(var i:int = 0; i &lt; myArray.length; i++) {

//for(var i:int = 0; i &lt; myArrayBullets.length; i++) {

var dx:Number = spaceship.x - myArray*.x;
var dy:Number = spaceship.y - myArray*.y;

var angle:Number = Math.atan2(dy, dx);

myArrayBulletsXspeed = Math.cos(angle) * myArrayBulletsSpeed;
myArrayBulletsYspeed = Math.sin(angle) * myArrayBulletsSpeed;

myArrayBullets.x = myArray*.x;
myArrayBullets.y = myArray*.y;
myArrayBullets.rotation = myArray*.rotation;

myArrayBulletsFired = true;
stage.addEventListener("enterFrame", updatemyArrayBullets);
//}
}
``````

}

function updatemyArrayBullets(evt:Event){

``````//for(var i:int = 0; i &lt; myArrayBullets.length; i++) {

myArrayBullets.x += myArrayBulletsSpeed;
myArrayBullets.y += myArrayBulletsSpeed;

if(spaceship.hitTestPoint(myArrayBullets.x, myArrayBullets.y, true)){
trace("hituser");
}

if(myArrayBullets.x &lt; -100 || myArrayBullets.x &gt; stage.stageWidth + 50 || myArrayBullets.y &lt; -100 || myArrayBullets.y &gt; stage.stageHeight + 50){
myArrayBulletsFired = false;
stage.removeEventListener("enterFrame", updatemyArrayBullets);
//removeChild(myArrayBullets);
}
//}
``````

}[/AS]