文王武帅

画圆

     今天做了一个小小的画圆的程序,就和flash里面的工具面板上画圆的工具类似的功能;代码如下:

import flash.events.MouseEvent;
import flash.display.Shape;
import flash.events.Event;

var chuX:Number;
var chuY:Number;
stage.addEventListener(MouseEvent.MOUSE_DOWN,onDown)
stage.addEventListener(MouseEvent.MOUSE_UP,onUp)
var shape:Shape=new Shape();
function drawYuan(xx:Number,yy:Number,r:Number):void
{
	
        shape.graphics.lineStyle(1);
	shape.graphics.drawCircle(xx,yy,r);
        shape.graphics.endFill();
	stage.addChild(shape);
	
}
function onDown(e:MouseEvent):void
{
	chuX=mouseX;
	chuY=mouseY;
	stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove)
}
function onMove(e:MouseEvent):void
{
        shape.graphics.clear();
        drawYuan((mouseX+chuX)/2,(mouseY+chuY)/2,Math.sqrt((mouseX-chuX)*(mouseX-chuX)+(mouseY-chuY)*(mouseY-chuY))/2);
    
}
function onUp(e:MouseEvent):void
{   
        stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
	var shape1:Shape=new Shape();
	shape1.graphics.lineStyle(1);
	shape1.graphics.drawCircle((mouseX+chuX)/2,(mouseY+chuY)/2,Math.sqrt((mouseX-chuX)*(mouseX-chuX)+(mouseY-chuY)*(mouseY-chuY))/2);
        shape1.graphics.endFill();
        stage.addChild(shape1);
    
}

  

posted on 2012-10-17 21:58  文王武帅  阅读(198)  评论(0)    收藏  举报

导航