1 Replies - 1143 Views - Last Post: 21 May 2009 - 12:31 PM

#1 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1490
  • View blog
  • Posts: 8,217
  • Joined: 07-September 06

MovieClip.drawRectangle and MovieClip.drawCircle

Posted 18 September 2008 - 07:18 PM

Description: Just copy and paste into a .fla file and you will be able to use. Clarifications: drawRectangle has the parameter called bgStyle which is a string. This takes "Gradient", "Solid" or "None" as valid values drawRectangle has the parameter bgColors, which is an array. This takes a tuple (Array of length 2) of colors.Basic MovieClip extension functions to draw a rectangel and circle. Comes with examples
MovieClip.prototype.drawRectangle = function(w:Number, h:Number, border:Number, borderColor:Color, bgStyle:String, bgColors:Array){
	this.lineStyle(border, borderColor, 100);
	if(bgStyle == "Gradient"){
		var alphas:Array = [100, 100];
		ratios:Array = [0, h*1.5];
		var matrix:Object = {matrixType:"box", x:0, y:0, w:430, h:150, r:Math.PI/2};
		this.beginGradientFill("linear", bgColors, alphas, ratios, matrix);
	}
	else if(bgStyle == "Solid"){
		this.beginFill(bgColors[0], 100);
	}
	this.lineTo(w, 0);
	this.lineTo(w, h);
	this.lineTo(0, h);
	this.lineTo(0, 0);
	if(bgStyle != "None"){
		this.endFill();
	}
}
MovieClip.prototype.drawCircle = function(r:Number, x:Number, y:Number, bgColor:Color){
	this.beginFill(bgColor, 100);
	this.moveTo(x+r, y);
	var A:Number = Math.tan(22.5 * Math.PI/180);
	for (var angle:Number = 45; angle<=360; angle += 45) {
		var endx:Number = r*Math.cos(angle*Math.PI/180);
		var endy:Number = r*Math.sin(angle*Math.PI/180);
		var cx:Number = endx+r*A*Math.cos((angle-90)*Math.PI/180);
		var cy:Number = endy+r*A*Math.sin((angle-90)*Math.PI/180);
		this.curveTo(cx+x, cy+y, endx+x, endy+y);
	}
}

var mc:MovieClip = _root.createEmptyMovieClip("test", 10);
mc.drawRectangle(100, 50, 2, 0x003300, "Gradient", [0x000000, 0xffffff]);

var mc2:MovieClip = _root.createEmptyMovieClip("test2", 11);
mc2.drawCircle(10, 50, 100, 0x003300);


Is This A Good Question/Topic? 0
  • +

Replies To: MovieClip.drawRectangle and MovieClip.drawCircle

#2 WhidbeyTomas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-May 09

Re: MovieClip.drawRectangle and MovieClip.drawCircle

Posted 21 May 2009 - 12:31 PM

Looks like this is AS2 code. I don't see any addChild().
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1