actionscript 3 - TypeError: Error #2007: Parameter hitTestObject must be non-null. Why -


so im trying make bullet-ship hittestobject ,but don`t know why variable representing bullets.length doest change.

so error comes function

function doships() {       trace("bcount :" + bcount)       trace("_bulletsarray length:" + _bulletsarray.length)       (var i:int = shiparray.length - 1; >= 0; i--) {                 shiparray[i].movedown() //what code in ship , ship2 class -> only: this.y += 3                 (var bcount= _bulletsarray.length-1; bcount >= 0; bcount--) {                           //if bullet touching ship                                     while (shiparray[i].hittestobject(_bulletsarray[bcount])) {                                     //if here means there`s collision                                       removechild(_bulletsarray[bcount]);                                     _bulletsarray.splice(bcount,1);                                     removechild(shiparray[i]);                                     shiparray.splice(i,1);                           }                 }       } 

}

before have shoot function shoots bullets , puts them in _bulletsarray.

when traces come showing : when dont shoot bullets gives me this

_bulletsarray length: 0 bcount: 0 

and when shoot gives me :

bcount: 0 _bulletsarray length: 1 

or

 bcount: 0 _bulletsarray length: 2 

so why doesnt bcount change when the _bulletsarray changes , when telling in for (var bcount= _bulletsarray.length-1; bcount >= 0; bcount--) { worse - when datatype 'bcount number 'bcount:number' gives me nan

since iterating length-1 down 0, value of bcount 0 when loop exits value trace show.

the null parameter error because remove colliding ship , bullet, , on next loop of while statement test objects in arrays @ same indices first time. if of objects happened @ end of array, position null. fix replace while-loop if statement.

in general have careful when change arrays while iterating on elements, becuase position of objects change, , have (like did) iterate last element first.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -