Error #1009, ActionScript 3, Bullet is null -


typeerror: error #1009: cannot access property or method of null object reference. @ main_fla::maintimeline/bulletfire()[main_fla.maintimeline::frame32:68]. occurring , have no idea why...please help, has been days of me troubleshooting , lost. thanks, also, reason when fire bullet goes @ 45 degrees , 225 degrees...thanks guys

    //create array hold multiple sprites var myspriteholder:array = []; //create counter keep track of number of sprites var lbcounter:int = 0; //maximum number of sprites on canvas var maxlb:int = 1; //keypress code stage.addeventlistener(mouseevent.click, dropbullet); //function mouse event fire bullet function dropbullet(evt:mouseevent):void{       var bcos:number = math.cos((turret.rotation) * math.pi / 180);      var bsin:number = math.sin((turret.rotation) * math.pi / 180);       //starting x , y      var startx:number = turret.x + (15 * bcos);      var starty:number = turret.y + (15 * bsin);      //calculates bullet needs go aiming in front of gun     var endx:number = turret.x + (50 * bcos);     var endy:number = turret.y + (50 * bsin);      var bullet:movieclip = new bullet();      bullet.x = startx;     bullet.y = starty;      bullet.xspeed = (endx - startx)/5;     bullet.yspeed =  (endx - startx)/5;      myspriteholder.push(bullet);     stage.addchild(bullet);      //this calls move down function     stage.addeventlistener(event.enter_frame,bulletfire); } //function shoot bullet function bulletfire(evt:event):void{     var bullet:movieclip;     //use loop move bullets     for(var i:int=0; i<=myspriteholder.length; i++){         bullet = myspriteholder[i];     //bounds collision     if(bullet.hittestobject(up)){         bullet.yspeed*=-1;     }     if(bullet.hittestobject(lower)){         bullet.yspeed*=-1;     }     if(bullet.hittestobject(left)){         bullet.xspeed*=-1;     }     if(bullet.hittestobject(right)){         bullet.xspeed*=-1;     }     //blockade collision     for(var t in myblockadeholder){             if(bullet.hittestobject(myblockadeholder[t])){                 trace("test");             }         }     //target collision         for(var c in mytargetholder){             if(bullet.hittestobject(mytargetholder[c])){             stage.removechild(bullet);             myspriteholder.splice(i,1);             lbcounter --;             mytargetholder[c].y = math.random()*390 + 10;             mytargetholder[c].x = math.random()*390 + 10;                 while(mytargetholder[c].hittestobject(turret)){                     mytargetholder[c].y = math.random()*390 + 10;                     mytargetholder[c].x = math.random()*390 + 10;                 }             }             for(var in mytargetholder){                 for(var s in mytargetholder){                     while(mytargetholder[a].hittestobject(mytargetholder[s])&& a!=s){                         mytargetholder[a].y = math.random()*390 + 10;                         mytargetholder[a].x = math.random()*390 + 10;                     }                 }                 for(var g in myblockadeholder){                     while(mytargetholder[a].hittestobject(myblockadeholder[g])&& a!=g){                         mytargetholder[a].y = math.random()*390 + 10;                         mytargetholder[a].x = math.random()*390 + 10;                     }                 }             }         }         bullet.y += bullet.yspeed;         bullet.x += bullet.xspeed;     } } 

myspriteholder.splice(i,1); 

this line causing unexpected results (and possibly error) you're splicing objects array loop working incrementally from. it's important understand when splice object in as3 you're removing element , indices follow move down splicing amount. try working backwards in loop instead:

 for(var i:int=myspriteholder.length-1; i>=0; i--){ 

also, line should moved out of mouseclick event you're adding multiple enter_frame events every time bullet placed. right it's going additional bulletfire() pass every time mouse click:

stage.addeventlistener(event.enter_frame,bulletfire); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -