So im trying to make a bullet-ship hitTestObject ,but i don`t know why the variable representing the bullets.length doest change.
so the error comes from this function
function doShips() {
trace("bcount :" + bcount)
trace("_bulletsArray length:" + _bulletsArray.length)
for (var i:int = shipArray.length - 1; i >= 0; i--) {
shipArray[i].moveDown() //what the code in the Ship and Ship2 class does -> only: this.y += 3
for (var bcount= _bulletsArray.length-1; bcount >= 0; bcount--) {
//if the bullet is touching the ship
while (shipArray[i].hitTestObject(_bulletsArray[bcount])) {
//if we get here it means there`s is a collision
removeChild(_bulletsArray[bcount]);
_bulletsArray.splice(bcount,1);
removeChild(shipArray[i]);
shipArray.splice(i,1);
}
}
}
}
before that i have also a shoot function that shoots bullets and puts them in the _bulletsArray.
when the traces come it is showing : when i dont shoot bullets it gives me this
_bulletsArray length: 0
bcount: 0
and when i shoot it gives me this :
bcount: 0
_bulletsArray length: 1
or
bcount: 0
_bulletsArray length: 2
so why doesnt the bcount change when The the _bulletsArray changes , when i am telling it to do so in the for (var bcount= _bulletsArray.length-1; bcount >= 0; bcount--) {
even worse - when i datatype the 'bcount to a number 'bcount:Number' it gives me NaN