直接粘贴代码就可以看到效果
var b:Point=new Point();
var circle:Sprite = new Sprite();
var test:Sprite=new Sprite();
test.x=200;
test.y=200;
circle.graphics.beginFill(0xFFCC00);
circle.graphics.drawCircle(0, 0, 10);
test.addChild(circle);
addChild(test)
circle.addEventListener(MouseEvent.MOUSE_DOWN,cd);
stage.addEventListener(MouseEvent.MOUSE_UP,sd);
function cd(e:MouseEvent) {
test.addEventListener(Event.ENTER_FRAME,line);
}
function sd(e:MouseEvent) {
circle.alpha=1
test.removeEventListener(Event.ENTER_FRAME,line);
}
function line(e:Event) {
b.x=test.mouseX;
b.y=test.mouseY;
if (b.length>100) {
b.normalize(100);//主要是这个方法实现半径为100的圆形范围
}
circle.x=b.x;
circle.y=b.y;
circle.alpha=.5
test.graphics.clear();
test.graphics.lineStyle(1);
test.graphics.lineTo(b.x,b.y);
}