actionscript 3 - How do I scroll with an object class that is added to the stage? -


hello people have small question: how make "map" object (platforms) moving (scrolling) when added stage , defined in own class? have scrolling text in code keeps giving me error saying i'm accessing property of null object. tried make definition object within class didn't help. can tell me i'm doing wrong?

package {  import flash.display.movieclip; import flash.events.keyboardevent; import flash.events.event; import flash.geom.point;  public class bro extends movieclip  {     //define class determining variables     private var moveup:boolean;     private var moveleft:boolean;     private var movedown:boolean;     private var moveright:boolean;     private var jumping:boolean;     private var movespeedr:uint;     private var movespeedy:number;     private var hittestradius:number;     private var hittestangle:number;     private var convertframetosecond:number;     private var checker:uint;      private var barrier:obstacles;      private var dsttomc:number;     private var fluidity:int;     private var varoffset:int;     private var varuno:int;     private var vardos:int;  public function bro() {         init();     } protected function init(){         //moveup=false;         moveleft=false;         //movedown=false;         moveright=false;         //jumping == false;         movespeedr=2;         movespeedy =0;         hittestradius=29.35;/*58.7/2*/         convertframetosecond = 1/30;         checker = 0;          dsttomc = this.x -((constants.stageref.stagewidth/2) + varoffset);         fluidity = 5;         varoffset = 10;         varuno = dsttomc/fluidity;         vardos = dsttomc/fluidity;          constants.stageref.addeventlistener(keyboardevent.key_down,keypressedlistener);         constants.stageref.addeventlistener(keyboardevent.key_up,keyreleasedlistener);         constants.stageref.addeventlistener(event.enter_frame,framelistener);         constants.stageref.addeventlistener(event.enter_frame, jump);         constants.stageref.addeventlistener(event.enter_frame, scrolling);         constants.stageref.addeventlistener(event.enter_frame, initiate);     }      //when press down key     private function keypressedlistener(e:keyboardevent){         var key:uint=e.keycode;         if(key==87||key==38)         {//w /             moveup=true;         }         else if(key==65||key==37)         {//a / left             moveleft=true;         }         else if(key==68||key==39){//d / right             moveright=true;         }         else if (key == 32)         {             movespeedy = -15;         }     }      //when release key     private function keyreleasedlistener(e:keyboardevent){         var key:uint=e.keycode;         /*if(key==87||key==38)         {//w /             moveup=false;         }*/         /*else*/ if(key==65||key==37)         {//a / left             moveleft=false;         }         else if(key==68||key==39)         {//d / right             moveright=false;         }     }      //every frame (30 times second)     private function framelistener(e:event)     {         /*if(moveup){             this.y-=movespeedr;         }*/         if(moveleft){             this.x-=movespeedr;         }         if(moveright){             this.x+=movespeedr;         }          while(hittestpointangle(constants.wallsref, this.x, this.y, hittestradius, 180)){             if(hittestangle>180)             {                 this.x-=0.125*math.sin(math.pi/180*hittestangle);                 this.y+=0.125*math.cos(math.pi/180*hittestangle);             }             else             {                 this.x+=0.125*math.sin(math.pi/180*hittestangle);                 this.y-=0.125*math.cos(math.pi/180*hittestangle);             }         }     } /**/private function scrolling(e:event) {     //finding player's position in respect center of stage     //stands distance main character       //add in "ground" later; focus on canvas     if(dsttomc < 0)     {         dsttomc *=-1;     }      if(this.x < (constants.stageref.stagewidth/2))     {          barrier.x += varuno;         this.x += varuno;         /*mysterybox.x += varuno;         monssprite.x += varuno;         barsprite.x += varuno;*/     }     //possibly change regular if statement; might interfere initial if statement         else if(this.x > (constants.stageref.stagewidth/2))         {             barrier.x -= vardos;             this.x -= vardos;             /*mysterybox.x -= vardos;             monssprite.x -= vardos;             barsprite.x -= vardos;*/         }        }     private function initiate(angled:event):void     {         if(constants.wallsref.hittestpoint(this.x, this.y+hittestradius-0.125,false)/*0.015625&& jumping == false*/)         {             constants.stageref.addeventlistener(event.enter_frame, jump);         }     }     private function jump(angled:event):void     {              //the player not allowed double jump             jumping = true;             //when character leaves ground             //this statement makes speed decreasing result of gravity.             movespeedy += convertframetosecond  *(9.8)/*gravity constant*/;             //(1/2)*a*t^2             this.y += movespeedy;             if(constants.wallsref.hittestpoint(this.x, this.y+hittestradius-.125,true)/*& jumping == true*/)             {                 movespeedy= 0;                 //this resets person on top of "ground"                 //this.y = 366.6 - this.height;                 //constants.stageref.removeeventlistener(event.enter_frame,jump);                 //now player can jump again                 jumping = false;             }             //this value deccelerates upward until hits maximum. point accelerate downward         //}     }     private function hittestpointangle(barrier:obstacles, xpos:number, ypos:number, radius:number, samples:uint):boolean{         const sample:number=0.5/samples;         var dx:number;         var dy:number;         var angle:number;         //number of points hit boxes         var hits:array=[];          var i:int=samples;         while(i>0){             i--;             angle =(2*math.pi)*(i*sample);             dx = radius*math.cos(angle);             dy = radius*math.sin(angle);             if(barrier.hittestpoint(xpos + dx, ypos + dy, true)){                 hits.push(new point(dx,dy));             }         }         if(hits.length==0){             return false;         }          var tx:number=0;         var ty:number=0;          i=hits.length;         while(i>0){             i--;             tx+=hits[i].x;             ty+=hits[i].y;         }         hittestangle=math.atan2(ty,tx)*(180/math.pi)-90;         return true;     } }} 

here's constants class:

package  as{ import flash.display.stage;  public class constants {      public static var stageref:stage;     public static var wallsref:obstacles;  }} 


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -