package { public class SimpleBallBouncer extends Sprite { private var ball:Ball; private var vx:Number; private var vy:Number; public function SimpleBallBouncer( ball:Ball ) { this.ball = ball; ball.x = 100; ball.y = 100; vx = Math.random() / 10; vy = Math.random() / 10; addEventListener(Event.ENTER_FRAME, onEnterFrame ); } public function onEnterFrame(event:Event):void { if ( ball.x + vx < 0 ) vx = 0 - vx; else if ( ball.x + ball.radius + vx >= stage.stageWidth ) vx = 0 - vx; if ( ball.y + mDeltaY < 0 ) vy = 0 - vy; else if ( ball.y + ball.radius + vy >= stage.stageHeight ) vy = 0 - vy; ball.x = ball.x + vx; ball.y = ball.y + vx; } } }