forked from: Screen Tearing Demonstration

by www0z0k
♥0 | Line 42 | Modified 2010-12-04 20:01:37 | MIT License
play

ActionScript3 source code

/**
 * Copyright www0z0k ( http://wonderfl.net/user/www0z0k )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/acTT
 */

// forked from ieshuaganocry's Screen Tearing Demonstration
package {
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    
    
    public class NewClass extends Sprite {
        
        private var balls : Array;  
        private const RADIUS:int = 50;
        private const SPEED:int = 10;
        
        public function NewClass() {
            balls = [];
            var ball : Shape;
            for (var i : int=0;i<20;i++) {
                ball = makeBall();
                ball.x = Math.floor(stage.stageWidth*Math.random());
                ball.y = Math.floor(stage.stageHeight*Math.random());
                addChild(ball);
                balls.push(ball);
            }
            addEventListener(Event.ENTER_FRAME,onEnterFrameHandler);
        }
        
        private function onEnterFrameHandler(event : Event) : void {
            var ball : Shape;
            for (var i : int = 0;i<balls.length;i++) {
                ball = balls[i];
                ball.y+=SPEED;
                if (ball.y-RADIUS>stage.stageHeight) {
                    ball.y = -RADIUS;
                    ball.x = Math.floor(Math.random()*stage.stageHeight);
                }
            }
        }

        
        private function makeBall() : Shape {
            var ball : Shape = new Shape();
            with (ball) {
                graphics.beginFill(0);
                graphics.drawCircle(0,0,RADIUS);
                graphics.endFill();
            }
            return ball;
        }

    }
}