Reputation: 19
I'm currently trying to make a circle using graphics.linestyle and graphics.drawCircle with a mouseclick. After the mouseclick I want the circle to expand on stage until the radius reach 150. I've tried with this code, but not getting it to work.
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;
}
}
}
Upvotes: 0
Views: 42
Reputation: 2558
radius
, you need to redraw the circle.This will fix it. You can run it in a blank project and it will compile and work. Just click anywhere on the background, and it'll run.
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);
}
}
Upvotes: 1