Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.MovieClip;
- import flash.events.MouseEvent;
- import flash.events.Event;
- import flash.geom.Point;
- import flash.display.Graphics;
- public class Main extends MovieClip
- {
- private var snapSize:int = 10;
- private var points:Array;
- private var halfStageHeight:Number;
- private var halfStageWidth:Number;
- public function Main() {
- halfStageWidth = stage.stageWidth/2;
- halfStageHeight = stage.stageHeight/2
- points = new Array();
- stage.addEventListener(MouseEvent.CLICK, onClick);
- stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
- graphics.beginFill(0xFF0000);
- graphics.drawCircle(halfStageWidth, halfStageHeight, 2);
- }
- private function onClick(e:MouseEvent):void
- {
- if(points.length > 1)
- {
- var ax = mouseX;
- var ay = mouseY;
- var bx = points[0].x;
- var by = points[0].y;
- if((bx - snapSize < ax && bx + snapSize > ax) && (by - snapSize < ay && by + snapSize > ay))
- {
- ax = bx;
- ay = by;
- stage.removeEventListener(MouseEvent.CLICK, onClick);
- stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
- }
- points.push(new Point(ax, ay));
- }
- else
- points.push(new Point(mouseX, mouseY));
- }
- private function onMouseMove(e:MouseEvent):void
- {
- if(points.length > 0)
- {
- graphics.clear();
- graphics.beginFill(0xFF0000);
- graphics.drawCircle(halfStageWidth, halfStageHeight, 2);
- graphics.lineStyle(4, 0xFFFFFF);
- graphics.beginFill(0xFFFFFF);
- graphics.moveTo(points[0].x, points[0].y);
- if(points.length > 1)
- {
- for(var i:int = 1; i < points.length; i++)
- graphics.cubicCurveTo(halfStageWidth, halfStageHeight, halfStageWidth, halfStageHeight, points[i].x, points[i].y);
- var ax = mouseX;
- var ay = mouseY;
- var bx = points[0].x;
- var by = points[0].y;
- if((bx - snapSize < ax && bx + snapSize > ax) && (by - snapSize < ay && by + snapSize > ay))
- {
- ax = bx;
- ay = by;
- }
- graphics.cubicCurveTo(halfStageWidth, halfStageHeight, halfStageWidth, halfStageHeight, ax, ay);
- }else
- graphics.cubicCurveTo(halfStageWidth, halfStageHeight, halfStageWidth, halfStageHeight, mouseX, mouseY);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement