我目前正在尝试使用graphics.linestyle和graphics.drawCircle用鼠标点击制作一个圆圈。点击鼠标后,我希望圆圈在舞台上展开,直到半径达到150.我已尝试使用此代码,但无法使其工作。
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.events.Event;
var circle:Sprite = new Sprite();
knapp.addEventListener(MouseEvent.CLICK, push);
function push (evt:MouseEvent) {
var radius:Number = 10;
var incRadius:Number = 3;
circle.graphics.lineStyle(3, 0xff000, 1);
circle.graphics.drawCircle(200, 200, radius);
addChild(circle);
circle.addEventListener(Event.ENTER_FRAME, increase);
function increase (evt:Event) {
if (radius <= 150) {
radius += incRadius;
}
}
}
答案 0 :(得分:1)
radius
后,您需要重新绘制圆圈。这将解决它。您可以在一个空白项目中运行它,它将编译和工作。只需点击背景上的任意位置即可运行。
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.events.Event;
var circle:Sprite = new Sprite();
addChild(circle);
var radius:Number = 10;
var incRadius:Number = 3;
stage.addEventListener(MouseEvent.CLICK, push);
function push(e:MouseEvent) {
radius = 10;
circle.graphics.clear();
circle.graphics.lineStyle(3, 0xff000, 1);
circle.graphics.drawCircle(0, 0, radius);
circle.x = stage.mouseX;
circle.y = stage.mouseY;
circle.addEventListener(Event.ENTER_FRAME, increase);
}
function increase(e:Event) {
radius += incRadius;
if (radius > 150) {
circle.removeEventListener(Event.ENTER_FRAME, increase);
} else {
circle.graphics.clear();
circle.graphics.lineStyle(3, 0xff000, 1);
circle.graphics.drawCircle(0, 0, radius);
}
}