actionscript 3 - TypeError: Error #1009: Cannot access a property or method of a null object reference. This code works most of time but a few times generate errors -


i stuck last 2 days; no sleep @ due stupid error. same code runs , generates error, trace it; works , not. pasting whole cs3 code. please guide me. these 2 lines generating errors are
64:
if(movieclip(charvector[i]).visible==true)updateobjectposition(charvector[i],charpoints[i]);
, 110:
textfield(txtscoregot.getchildbyname("txtscorehit")).text=e1.tostring();

var lastx:int=stage.mousex; var totallives:int=3; var totalallowedlives:int=3; var timercounter:int=0 var currentobjectsfalling:int=0; var score:int=0; var speed:int=4; var charvector:array=new array(point5, point6, point9, point10, point15, point20, rocket, speedbreaker, life, poison); var charpoints:array=new array(5,6,9,10,15,20,0,3,50,-20) for(var i:int=0; i<=9;i++) movieclip(charvector[i]).visible=false; stop(); btnplayagain.visible=false; btnplayagain.addeventlistener(mouseevent.click, mybuttonclick); txtscoregot.visible=false; function mybuttonclick(ev:mouseevent):void {     gotoandstop(2);     ev.updateafterevent(); } //function startplay() {     var mytimer:timer = new timer(20, 0);     mytimer.addeventlistener("timer",timerhandler);     mytimer.start();     mouse.hide();     txtlives.text=totallives.tostring();     txtspeed.text=speed.tostring();     stage.addeventlistener(mouseevent.mouse_move, updateplayerposition);     stage.addeventlistener(mouseevent.mouse_down, speedup);     stage.addeventlistener(mouseevent.mouse_up, speednormal); //} function speedup(e:mouseevent) {     speed+=5;     txtspeed.text=speed.tostring();     e.updateafterevent(); } function speednormal(e:mouseevent) {     if(speed<=5) speed=1 else speed-=5;     txtspeed.text=speed.tostring();     e.updateafterevent(); } function timerhandler(event:timerevent):void {     timercounter++;     txtlives.text=totallives.tostring();     if(timercounter==10)     {         timercounter=0;         if(currentobjectsfalling<3)         {             var tmpa:int= math.floor(math.random()*10);             if((tmpa==8 && life.visible==false && totalallowedlives>0) || movieclip(charvector[tmpa]).visible==false && tmpa!=8)             {                     var tmpmoive:movieclip= charvector[tmpa];                     tmpmoive.visible=true;                     tmpmoive.y=-tmpmoive.height;                     tmpmoive.x=math.random()*(stage.width-5-tmpmoive.width);                     currentobjectsfalling++;             }         }     }     for(i=0; i<=9;i++)         if(movieclip(charvector[i]).visible==true)updateobjectposition(charvector[i],charpoints[i]); } //startplay(); function updateplayerposition(e:mouseevent) {     var curx:int=stage.mousex;         if(curx<=55)         lastx=5;     else if(curx<lastx)         lastx=curx-50;     else if(curx>lastx)     {         if(curx>=stage.width-36)             lastx=stage.width-66;         else             lastx=curx-50;     }     player.x=lastx;     e.updateafterevent(); } function updateobjectposition(e:movieclip, e1:int) {     e.y+=speed;     if(e.y>stage.stageheight-5)     {         currentobjectsfalling=currentobjectsfalling-1;         e.visible=false;         e.y=-e.height;         score--;         txtscore.text=score.tostring();         txtscore.text=score.tostring();         txtscoregot.visible=true;         trace(e.name, e1);         textfield(txtscoregot.getchildbyname("txtscorehit")).text="-1"; //      txtscoregot.txtscorehit.text="-1";         txtscoregot.x=player.x;         txtscoregot.y=player.y-txtscoregot.height;     }     if(e.y+e.height>=player.y && e.y <= player.y+player.height)     {         if((e.x>=player.x && e.x<=player.x+player.width) || (e.x<=player.x && e.x + e.width>=player.x))         {             score+=e1;             txtscore.text=score.tostring();             txtscoregot.visible=true;             trace(e.name, e1);             textfield(txtscoregot.getchildbyname("txtscorehit")).text=e1.tostring();             txtscoregot.x=player.x;             txtscoregot.y=player.y-txtscoregot.height;             if(e1==0)             {                 speed++;                 txtspeed.text=speed.tostring();             }             if(e1==3 && speed>1)             {                 speed--;                 txtspeed.text=speed.tostring();             }             e.visible=false;             currentobjectsfalling--;             if(e1==50 && totalallowedlives>0)             {                 totalallowedlives--;                 totallives++;             }             if(e1==-20) totallives--;             if(totallives==0 || score==-50)             {                 btnplayagain.visible=true;                 mouse.show();                 mytimer.stop();                 stage.removeeventlistener(mouseevent.mouse_move,  updateplayerposition);                 stage.removeeventlistener(mouseevent.mouse_down, speedup);                 stage.removeeventlistener(mouseevent.mouse_up, speednormal);                 gotoandstop(3);             }         }     } } 


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -