Drawing Circles and Ellipses | Macromedia Flash

Macromedia Flash 5   Download SWF    Download zipped FLA

Click in the area and drag your mouse to create shapes. You can hold down the Shift key to draw perfect circles. You can delete the last shape by pressing the 'd' key, just make sure that flash has the keyboard focus. If you only need the minimal stuff necessary to draw ellipses and circles download: simple_circle.zip. The following methods are placed on the first frame of the main timeline:

/* calculate the axes of the ellipse
*************************************************/
MovieClip.prototype.getAxes = function() {
	var rx = Math.abs(this.radius._x - this.origo._x);
	var ry = Math.abs(this.radius._y - this.origo._y);
	/* rs is to check the size of the ellipse */
	var rs = rx + ry;
	return {rx: rx, ry: ry, rs: rs};
}

/* scales the ellipse
*************************************************/
MovieClip.prototype.scaleCircles = function() {
	var ax = this.getAxes();
	/* scale evenly when SHIFT key is pressed */
	if(Key.isDown(Key.SHIFT)) ax.rx = ax.ry = Math.sqrt(ax.rx * ax.rx + ax.ry * ax.ry);
	this[this.circles]._xscale = ax.rx;
	this[this.circles]._yscale = ax.ry;
}

/* create new ellipse
*************************************************/
MovieClip.prototype.addCircle = function(x, y) {
	this.circles++;
	this.attachMovie("circle", this.circles, this.circles);
	this[this.circles]._x = x;
	this[this.circles]._y = y;
	this[this.circles]._xscale = this[this.circles]._yscale = 1;
}

/* remove last ellipse
*************************************************/
MovieClip.prototype.deleteLastCircle = function() {
	if(this.circles > 0) {
		this[this.circles--].removeMovieClip();
	}
}

These events are attached to the host movieclip:

/* startup
*************************************************/
onClipEvent ( load ) {
	this.circles = 0;
	this.drawing = false;
	this.origo._visible = this.radius._visible = false;
}

/* create new ellipse and show locators
*************************************************/
onClipEvent ( mouseDown ) {
	var x = this.origo._x = this.radius._x = this._xmouse;
	var y = this.origo._y = this.radius._y = this._ymouse;
	this.origo._visible = this.radius._visible = true;
	this.radius.startDrag(true);
	this.addCircle(x, y);
	this.drawing = true;
}

/* finalize ellipse and hide locators
*************************************************/
onClipEvent ( mouseUp ) {
	this.radius.stopDrag();
	this.drawing = false;
	this.origo._visible = this.radius._visible = false;

	/* remove small ellipses that might be accidental
	*************************************************/
	if(this.getAxes().rs < 8) this.deleteLastCircle();
}

/* scale current ellipse
*************************************************/
onClipEvent ( mouseMove ) {
	if(this.drawing) {
		this.scaleCircles();
	}
}

/* delete last ellipse
*************************************************/
onClipEvent ( keyDown ) {
	if(!this.drawing) {
		if(Key.isDown(68)) this.deleteLastCircle();
	}
}
COMMENTS ARE CLOSED
Sorry, I do not have time to answer questions related to these scripts.
You can always get help on the Kirupa Flash Forums. Thank you for visiting.