package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* ...
* @author Jeetendra Singh
*/
public class Main extends Sprite
{
private var control1:Sprite;
private var control2:Sprite;
public function Main()
{
init();
}
private function init():void
{
control1 = new Circle();
control2 = new Circle();
addChild(control1);
addChild(control2);
control1.x = 500;
control1.y = 500;
control2.x = 500;
control2.y = 100;
control1.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
control2.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(Event.ENTER_FRAME, render);
}
private function onMouseDown(e:MouseEvent):void
{
Sprite(e.target).addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
Sprite(e.target).removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
Sprite(e.target).startDrag();
}
private function onMouseUp(e:MouseEvent):void
{
Sprite(e.target).removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
Sprite(e.target).addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
Sprite(e.target).stopDrag();
}
private function render(e:Event):void
{
var g:Graphics = this.graphics;
g.clear();
g.lineStyle(2, 0xff0000);
g.moveTo(200, 200);
g.cubicCurveTo(control1.x, control1.y, control2.x, control2.y, 400, 30);
}
}
}
// Helper Class
import flash.display.Sprite;
class Circle extends Sprite
{
public function Circle()
{
this.graphics.beginFill(0xff00ff, 1);
this.graphics.drawCircle(0, 0, 10);
}
}
Like this:
Like Loading...
Related
Hi! I’ve tried implementing this but I’m getting 1061: Call to a possibly undefined method cubicCurveTo through a reference with static type flash.display:Graphics. Thanks for posting this so quickly though, I’m very eager to get my hands on this new feature.
hi , are you using http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/playerglobal11_0.swc for compiling your code.