Flash player 11 cubicCurveTo Example


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);
	}
}

2 responses to “Flash player 11 cubicCurveTo Example

  1. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s