package { import flash.accessibility.Accessibility; import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Point; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="30")] public class FlashTest extends Sprite { //重力の設定 private const GRAVITY:Number = 0.9; //跳ね返り係数。跳ね返った後、減るスピードの率 private const BOUNCE:Number = -0.7; //摩擦係数 private const FRICTION:Number = 0.9; private var _target:Sprite; private var _speed:Point; private var _acc:Point; private var _mouse:Point; public function FlashTest() { var tf:TextFormat = new TextFormat(); tf.font = "_typewriter" tf.size = 12; var txt:TextField = new TextField(); txt.defaultTextFormat = tf; txt.text="ドラッグすると飛ぶ"; txt.autoSize = TextFieldAutoSize.LEFT; txt.x = stage.stageWidth /2 -txt.width/2; addChild(txt); _speed = new Point(); _acc = new Point(); _mouse = new Point(); _target = new Particle(); _target.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener); _target.x = Math.random()*(stage.stageWidth - _target.width) + _target.width/2; addChild(_target); addEventListener(Event.ENTER_FRAME, enterFrameListener); } private function mouseDownListener(e:MouseEvent):void{ } private function mouseUpListener(e:MouseEvent):void{ } private function enterFrameListener(e:Event):void{ graphics.clear(); _speed.y += GRAVITY; _speed.x += FRICTION; _target.x += _speed.x; _target.y += _speed.y; //衝突時には、反対方向のスピードを加算 if(stage){ } } // during _target is dragging private function enterFrameListener2(e:Event):void{ } } } import flash.display.Graphics; import flash.display.MovieClip; class Particle extends MovieClip{ public function Particle():void{ var gr:Graphics = graphics; gr.beginFill(0xCCCCCC * Math.random() + 0xCCCCCC, 0.9); gr.drawCircle(0, 50, 20); } } flash on 2010-2-5