User drawing multiple ellipses
Alright...I've got a program that needs to let the user draw ellipse a on the stage and I need to track the positions so I can re-draw them when they come back. I've got that mostly working, except, I need to let them draw up to 5 ellipses and be able to delete ones that they have already drawn so they can draw new ones.
I'm having difficulty managing the children, object numbering/naming, etc.
Here's the code that's working as far as drawing the ellipse:
Actionscript Code:
import flash.display.Sprite;
import flash.events.*;
import flash.ui.Mouse;
import flash.net.URLRequest;
stage.addEventListener(MouseEvent.MOUSE_MOVE, cursorFollow);
var drawCircleOn:Boolean = false;
var initX:Number;
var initY:Number;
var circleNum:Number = 0;
function cursorFollow(evt:MouseEvent):void
{
if (drawCircleOn)
{
circle.graphics.clear();
circle.graphics.lineStyle(2, 0x000000);
circle.graphics.beginFill(0xFFF500,.3);
circle.graphics.drawEllipse(initX, initY, mouseX-initX, mouseY-initY);
circle.graphics.endFill();
addChild(circle);
}
evt.updateAfterEvent();
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, setCircle);
stage.addEventListener(MouseEvent.MOUSE_UP, releaseCircle);
function setCircle(evt:MouseEvent):void
{
drawCircleOn = true;
initX = mouseX;
initY = mouseY;
}
function releaseCircle(evt:MouseEvent):void
{
drawCircleOn = false;
trace("ell "+initX+" , "+initY+" , "+(mouseX-initX)+" , "+(mouseY-initY));
}
var circle:Sprite = new Sprite();
I tried doing something like:
Actionscript Code:
for(var i:int=1;i<=5;i++){
var circle:Sprite = new Sprite();
circle.name = "circle" + i;
}
and then using a variable in the cursorFollow function, but that didn't let me create multiple circles...
TIA!