Guest User

Untitled

a guest
Jan 6th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package{
  2.     import flash.display.Sprite;
  3.  
  4.     public class Ball extends Sprite{
  5.         public var speed:int;
  6.        
  7.         public function Ball(){
  8.             this.graphics.beginFill(0xABCDEF);
  9.             this.graphics.drawCircle(0, 0, 5);
  10.             this.graphics.endFill();
  11.            
  12.             speed = int(Math.random()*20+1);
  13.         }
  14.        
  15.         public function destroy(){
  16.             this.graphics.clear();
  17.         }
  18.     }
  19. }
  20. ------------------------
  21. Frame 1
  22. ------------------------
  23.  
  24. import flash.events.Event;
  25. import flash.display.StageScaleMode;
  26. import flash.display.StageAlign;
  27. import flash.text.TextField;
  28. import flash.text.TextFormat;
  29.  
  30. stage.scaleMode = StageScaleMode.NO_SCALE;
  31. stage.align = StageAlign.TOP_LEFT;
  32.  
  33. var txt:TextField = new TextField();
  34.     txt.setTextFormat(new TextFormat("Arial", 12, 0x000000));
  35.     txt.x = txt.y = 5;
  36.     this.addChild(txt);
  37.  
  38. var balls:Vector.<Ball> = new Vector.<Ball>();
  39. var ball:Ball;
  40. var i:int;
  41.  
  42. stage.addEventListener(Event.ENTER_FRAME, iterator);
  43. function iterator(event:Event){
  44.     // Create a new ball every frame
  45.     ball = new Ball();
  46.     balls.push(ball);
  47.    
  48.     // Place ball at random location
  49.     ball.x = stage.stageWidth*Math.random();
  50.     this.addChild(ball);
  51.    
  52.     // Move existing balls
  53.     for(i=0; i<balls.length; i++){
  54.         balls[i].y += balls[i].speed;
  55.        
  56.         // Delete ball if out of bounds
  57.         if(balls[i].y > stage.stageHeight){
  58.             this.removeChild(balls[i]);
  59.             balls[i].destroy();
  60.             balls.splice(i, 1);
  61.         }
  62.     }
  63.     txt.text = String(balls.length);
  64. }
Add Comment
Please, Sign In to add comment