ドラッグドロップで動く awef forked:1favorite:6lines:100license : MIT License modified : 2009-08-18 16:18:20 Embed Tweet package { import flash.display.Sprite; import gs.TweenMax; import gs.easing.*; [SWF(width = "465", height = "465", backgroundColor = 0xEEEEEC, frameRate = "60")] public class main extends Sprite { public function main() { for (var i:int = 0; i < 15; i++) { addChild(new obj()); } } } } import flash.display.Sprite; import flash.events.MouseEvent; import flash.filters.DropShadowFilter; import gs.TweenMax; import gs.easing.*; class obj extends Sprite { private var body:Sprite = new Sprite(); private var marker:Sprite = new Sprite(); private var arrow:Sprite = new Sprite(); function obj() { addChild(body); addChild(marker); addChild(arrow); //ボディの描写 var s:int = 18; body.graphics.beginFill(0); body.graphics.drawRect(-s / 2, -s / 2, s, s); body.graphics.endFill(); body.graphics.lineStyle(s / 10, 0xFFFF00); body.graphics.moveTo(-s / 4, -s / 4); body.graphics.lineTo(-s / 4, -s / 2); body.graphics.moveTo(s / 4, -s / 4); body.graphics.lineTo(s / 4, -s / 2); body.buttonMode = true; x = Math.floor(Math.random() * 465); y = Math.floor(Math.random() * 465); body.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); } private function onMouseDown(e:MouseEvent):void { stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp, false); stage.addEventListener(MouseEvent.MOUSE_MOVE, drawArrow, false); //マーカーを非表示で描写 marker.scaleX = 0; marker.scaleY = 0; marker.alpha = 0.6; marker.graphics.lineStyle(2, 0xFF0000); marker.graphics.drawCircle(0, 0, 16); marker.graphics.moveTo( -20, 0); marker.graphics.lineTo( -12, 0); marker.graphics.moveTo(20, 0); marker.graphics.lineTo(12, 0); marker.graphics.moveTo(0, -20); marker.graphics.lineTo(0, -12); marker.graphics.moveTo(0, 20); marker.graphics.lineTo(0, 12); //マーカーを回転させる TweenMax.to(marker, 3, { rotation : marker.rotation + 360, loop : 0, ease : Linear.easeNone } ); //マーカーを表示させる TweenMax.to(marker, 0.1, { scaleX : 1, scaleY : 1, ease : Cubic.easeIn } ); } private function drawArrow(e:MouseEvent):void { arrow.graphics.clear(); arrow.graphics.lineStyle(2, 0xFF0000, 0.6); arrow.graphics.moveTo(0, 0); arrow.graphics.lineTo(mouseX, mouseY); arrow.graphics.beginFill(0xFF0000, 0.4); arrow.graphics.drawCircle(mouseX, mouseY, 8); } private function onMouseUp(e:MouseEvent):void { stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp); stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawArrow); arrow.graphics.clear(); TweenMax.to(marker, 0.1, { alpha : 0, ease : Linear.easeNone, onComplete : function():void { marker.graphics.clear(); TweenMax.killTweensOf(marker); } }); goto(e.stageX, e.stageY); } private function goto(argX:int, argY:int):void { var rTarget:int = -Math.atan2(x - argX, y - argY) / Math.PI * 180; if (rTarget < 0 && Math.abs(rotation - rTarget) > 180) rTarget += 360; if (rTarget > 0 && Math.abs(rotation - rTarget) > 180) rTarget -= 360; var rTime:Number = Math.abs(rotation - rTarget) / 180; TweenMax.to(this, rTime, { rotation : rTarget, ease : Linear.easeNone, overwrite :1 } ); TweenMax.to(this, Math.sqrt(Math.pow(x - argX, 2) + Math.pow(y - argY, 2)) / 50, { delay : rTime, x : argX, y : argY , ease : Linear.easeNone } ); } } Code Fullscreen Preview Fullscreen heckmeck ngtn xor sw_lucchini teageek siouxcitizen.. Math.abs MouseEvent.MOUSE_MOVE removeEventListener MouseEvent.MOUSE_UP Math.pow MouseEvent mouseY mouseX addChild buttonMode Math.floor stageY stageX rotation addEventListener alpha scaleY scaleX Math.atan2 MouseEvent.MOUSE_DOWN sort new page view favorite forked pv0 forked from: ドラッグドロップで動く reborn0926 forked:0 favorite:0lines:100 (diff:1)