flash player 9
package
{
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
//Tweenerクラスと利用するプロパティクラスをimport
import caurina.transitions.Tweener;
import caurina.transitions.properties.CurveModifiers;
public class Main extends flash.display.Sprite
{
private var destinationX:Number;
private var destinationY:Number;
private var pointerA:Pointer;
private var pointerB:Pointer;
private var pointerBezier:Pointer;
private var ball:Ball;
private var isFollowing:Boolean = true;
private var line:Shape;
public function Main():void
{
init();
}
private function init():void {
//SpecialPropertyの初期化
CurveModifiers.init();
pointerA = new Pointer(30, 30, 10, 0x333333);
pointerB = new Pointer(400, 300, 10, 0x333333);
pointerBezier = new Pointer(70, 150, 8, 0xffcc00);
ball = new Ball(pointerA.x, pointerA.y, 8, 0xff6600);
line = new Shape();
addChild(line);
addChild(pointerB);
addChild(pointerA);
addChild(pointerBezier);
addChild(ball);
stage.addEventListener(MouseEvent.CLICK, clickHandler);
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function easeTo():void {
//trace(destinationX, destinationY);
//メイン
Tweener.addTween(ball,
{ x:destinationX, y:destinationY, _bezier: { x:pointerBezier.x, y:pointerBezier.y }, time:2.5,
transition:"easeInOutCubic", onComplete:change } );
}
private function change():void {
isFollowing = !isFollowing;
destinationX = isFollowing ? pointerB.x : pointerA.x;
destinationY = isFollowing ? pointerB.y : pointerA.y;
easeTo();
}
private function clickHandler(event:MouseEvent):void {
stage.removeEventListener(MouseEvent.CLICK, clickHandler);
destinationX = pointerB.x;
destinationY = pointerB.y;
easeTo();
}
private function enterFrameHandler(event:Event):void {
var g:Graphics = line.graphics;
g.clear();
g.lineStyle(0, 0xcccccc);
g.moveTo(pointerA.x, pointerA.y);
g.lineTo(pointerBezier.x, pointerBezier.y);
g.lineTo(pointerB.x, pointerB.y);
}
}
}