Pages: [1]
  Print  
Author Topic: invisible targets  (Read 5895 times)
0 Members and 1 Guest are viewing this topic.
tobytooga
Apprentice

Brians: 0
Offline Offline

Posts: 1


Email
« on: May 07, 2012, 12:38:17 AM »

for some reason the game runs fine and finds no errors but it wont run the targets to shoot at, i think theres some problem with adding them to stage but cant quite see it.

var TargetTime:int = 1;          
var TargetLimit:int = 40;

if(TargetTime < TargetLimit){
   TargetTime ++;
}
   else {
      var newTarget = new Target ();
      newTarget.y = -1 * newTarget.height;
      newTarget.x = int(Math.random()*stage.stageWidth - newTarget.width);
      addChild(newTarget);
      TargetTime = 0;
   }

and the seperate .as file:
package{
   import flash.display.MovieClip;         
   import flash.events.*;            
   public class Target extends MovieClip{
      private var _root:Object;
      private var speed:int = 10;     
      public function Target(){
addEventListener(Event.ADDED, beginClass);      
addEventListener(Event.ENTER_FRAME, eFrame);   
}
      private function beginClass(event:Event):void{
         _root = MovieClip(root);
      }
      private function eFrame(event:Event):void{
         y += speed;
         if(this.y > stage.stageHeight){
            removeEventListener(Event.ENTER_FRAME, eFrame);
            _root.removeChild(this);
         }
      }
   }
}



can anybody see whats wrong?
   
Logged
Pages: [1]
  Print  
 
Jump to:  


About howtothinklikeaprogrammer.com
Terms of service | Privacy policy

Paul Vickers is a participant in the Amazon Europe S..r.l. Associates Programme, an affiliate advertising programme designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.co.uk/Javari.co.uk.

How to think like a programmer: problem solving for the bewildered pdf
How to think like a programmer: program design solutions for the bewildered pdf
Powered by EzPortal