Ball类
package { import flash.display.MovieClip; import flash.events.Event; import flash.utils.Timer; import flash.events.TimerEvent; /** * ... * @author ycy 2008.3.18 */ public class Ball extends MovieClip { private var t:Timer; private const G:Number = 0.1; private var vy:Number = 0; public function Ball() { t = new Timer(10); t.addEventListener(TimerEvent.TIMER, move); t.start(); } public function move(e:Event):void { vy += G; this.y += vy; if (y > 370) { this.y = 370; vy *= -0.9; trace(vy); if (Math.abs(vy) < 0.8) { this.y = 370; t.removeEventListener(TimerEvent.TIMER,move); } } } } }
Main文档类
package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; /** * ... * @author ycy 2008.3.18 */ public class Main extends MovieClip { public function Main() { stage.addEventListener(MouseEvent.CLICK,clickHandle); } private function clickHandle(e:Event):void { var ball:Ball = new Ball(); ball.x = mouseX; ball.y = mouseY; addChild(ball); } } }
2008.3.18