graphics.clear(); graphics.lineStyle(3,0x0000FF,1); graphics.moveTo(0,315); graphics.lineTo(stage.stageWidth, 315); graphics.lineStyle(1,0xFF0000, 1); var top = false; var ymov = 0; var bouancy = -2; var gravity = 4; var mass = 1; var yAccel = (bouancy + gravity) / mass; ball.buttonMode = true; stage.addEventListener(Event.ENTER_FRAME, moveBall); ball.addEventListener(MouseEvent.MOUSE_DOWN, pickUpBall); ball.addEventListener(MouseEvent.MOUSE_UP, dropBall); function moveBall(event:Event):void { //add yAccel to ymov ymov += yAccel; //move the ball by changing the y property using the ymov variable ball.y += ymov; if(ymov > 0 && !top) { //draw a line using moveTo and lineTo from the left edge of the stage to the right edge of the stage // using ball.y makes the line height = middle of ball graphics.lineStyle(1, 0xFF00FF); graphics.moveTo(0,ball.y); graphics.lineTo(stage.stageWidth, ball.y); top = true; } if(ymov <0 && top) { top = false; } if(ball.y >= 300) { //set ball to an appropriate height, the blue line ball.y = 300; //reverse the direction of the ball, use the ymov variable ymov *= -1; //add .1 to the bouancy variable bouancy += .1; } if(bouancy >= 0) { stage.removeEventListener(Event.ENTER_FRAME, moveBall); } } function pickUpBall(event:MouseEvent):void { event.currentTarget.startDrag(); } function dropBall(event:MouseEvent):void { stopDrag(); bouancy = -2; stage.addEventListener(Event.ENTER_FRAME, moveBall); graphics.clear(); graphics.lineStyle(3,0x0000FF,1); graphics.moveTo(0,315); graphics.lineTo(stage.stageWidth, 315); graphics.lineStyle(1,0xFF0000, 1); }