flash on 2012-4-16
/**
* Copyright wyktor ( http://wonderfl.net/user/wyktor )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/eOLv
*/
package {
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var x1:Number = 250;
private var y1:Number = 300;
private var x2:Number = 200;
private var y2:Number = 200;
private var offset:Number = 50;
private var c2:Sprite = new Sprite();
private var s:Sprite;
public function FlashTest() {
// write as3 code here..
s = new Sprite();
addChild(s);
c2.x = x2;
c2.y = y2;
c2.graphics.beginFill(0x000000, 1);
c2.graphics.drawCircle(0,0, 10);
addChild(c2);
c2.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
c2.addEventListener(MouseEvent.MOUSE_UP, upHandler);
addEventListener(Event.ENTER_FRAME, loop)
}
public function downHandler(e:MouseEvent):void {
c2.startDrag();
}
public function upHandler(e:MouseEvent):void {
c2.stopDrag();
}
public function loop(e:Event):void{
x2 = c2.x;
y2 = c2.y;
var path:Object = {};
if(x1 > x2 && y1 > y2) {
path.x12 = x1 + offset;
path.y12 = y1;
path.x13 = path.x12;
path.y13 = y2 - offset;
path.xMiddle = x2 + ((x1 - x2) / 2);
path.yMiddle = path.y13;
path.x24 = x2 - offset;
path.y24 = y2 - offset;
path.x22 = x2 - offset;
path.y22 = y2;
//start at x1
//move to x1,2
//move to x1,3
//move to x2,4
//move to x2,2
//move to x2
s.graphics.clear();
s.graphics.lineStyle(1, 0xff6600, 1, true);
s.graphics.moveTo(x1, y1);
s.graphics.cubicCurveTo(path.x12, path.y12, path.x13, path.y13, path.xMiddle, path.yMiddle);
s.graphics.cubicCurveTo(path.x24, path.y24, path.x22, path.y22, x2, y2);
} else if(x1 < x2 && y1 > y2 || x1 < x2 && y1 < y2) {
path.x12 = x1 + offset;
path.y12 = y1;
path.x22 = x2 - offset;
path.y22 = y2;
s.graphics.clear();
s.graphics.lineStyle(1, 0xff6600, 1, true);
s.graphics.moveTo(x1, y1);
s.graphics.cubicCurveTo(path.x12, path.y12, path.x22, path.y22, x2, y2);
} else if(x1 > x2 && y1 < y2) {
path.x12 = x1 + offset;
path.y12 = y1;
path.x13 = path.x12;
path.y13 = y2 + offset;
path.xMiddle = x2 + ((x1 - x2) / 2);
path.yMiddle = path.y13;
path.x24 = x2 - offset;
path.y24 = y2 + offset;
path.x22 = x2 - offset;
path.y22 = y2;
s.graphics.clear();
s.graphics.lineStyle(1, 0xff6600, 1, true);
s.graphics.moveTo(x1, y1);
s.graphics.cubicCurveTo(path.x12, path.y12, path.x13, path.y13, path.xMiddle, path.yMiddle);
s.graphics.cubicCurveTo(path.x24, path.y24, path.x22, path.y22, x2, y2);
}
}
}
}