Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

BasicShapes.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*************** Example *******************\
this.shapeList = ["No Tool", "Square","Circle","SimpleCircle","SimpleCurve","Line"];
this.shapeList.pos = 0;
this.onMouseDown = function(){
	if (this.shape.onMouseMove) delete this.shape.onMouseMove;
	var tool = this.shapeList[this.shapeList.pos];
	if (this[tool]){
		var x = this._xmouse, y = this._ymouse;
		var centered = Key.isDown(Key.CONTROL)
		this.shape = this.createEmptyMovieClip("shape"+this.depth, this.depth++);
		this.shape.onMouseMove = function(){
			var w = this._parent._xmouse-x, h = this._parent._ymouse-y;
			if (Key.isDown(Key.SHIFT)) w = h = Math.max(Math.abs(w), Math.abs(h)); // if uniform scale
			this.clear();
			this[tool](x,y, w,h, centered, glstyle, gfstyle);
			updateAfterEvent();
		}
	}
}
this.onMouseUp = function(){
	delete this.shape.onMouseMove;
}
Key.addListener(this);
this.onKeyDown = function(){
	if (inc = Key.isDown(Key.UP) - Key.isDown(Key.DOWN)){
		this.shapeList.pos += inc;
		if (this.shapeList.pos >= this.shapeList.length) this.shapeList.pos = 0;
		else if (this.shapeList.pos < 0) this.shapeList.pos = this.shapeList.length - 1;
		trace(this.shapeList[this.shapeList.pos]);
	}
}
trace(this.shapeList[this.shapeList.pos] +" selected, Use the UP & Down keys to switch tools.\nThe CONTROL and SHIFT keys will toggle drawing styles.");
glstyle = [2,0,100];
gfstyle = [0xff,20];
\*********************************************/


MovieClip.prototype.Circle = function(x,y, w,h, centered, lstyle, fstyle) {
	w /= 2; h /= 2;
	if (!centered){
		x += w; y += h;
	}
	var xc1 = w*(Math.SQRT2-1), xc2 = w*Math.SQRT2/2;
	var yc1 = h*(Math.SQRT2-1), yc2 = h*Math.SQRT2/2;
	if (lstyle) lineStyle.apply(this, lstyle);
	if (fstyle) beginFill.apply(this, fstyle);
	this.moveTo(x+w, y);
	this.curveTo(x+w, y+yc1, x+xc2, y+yc2);
	this.curveTo(x+xc1, y+h, x, y+h);
	this.curveTo(x-xc1, y+h, x-xc2, y+yc2);
	this.curveTo(x-w, y+yc1, x-w, y);
	this.curveTo(x-w, y-yc1, x-xc2, y-yc2);
	this.curveTo(x-xc1, y-h, x, y-h);
	this.curveTo(x+xc1, y-h, x+xc2, y-yc2);
	this.curveTo(x+w, y-yc1, x+w, y);
	this.endFill();
	return this;
};
MovieClip.prototype.SimpleCircle = function(x, y, r, lstyle, fstyle) {
	var r2 = r*2;
	if (lstyle) lineStyle.apply(this, lstyle);
	if (fstyle) beginFill.apply(this, fstyle);
	this.moveTo(x-r, y-r);
	this.curveTo(x, y-r2, x+r, y-r);
	this.curveTo(x+r2, y, x+r, y+r);
	this.curveTo(x, y+r2, x-r, y+r);
	this.curveTo(x-r2, y, x-r, y-r);
	this.endFill();
	return this;
};
MovieClip.prototype.Square = function(x,y, w,h, centered, lstyle, fstyle){
	if (!centered){
		w /= 2; h /= 2;
		x += w; y += h;
	}
	if (lstyle) lineStyle.apply(this, lstyle);
	if (fstyle) beginFill.apply(this, fstyle);
	this.moveTo(x-w, y-h);
	this.lineTo(x+w, y-h);
	this.lineTo(x+w, y+h);
	this.lineTo(x-w, y+h);
	this.lineTo(x-w, y-h);
	this.endFill();
	return this;
};
MovieClip.prototype.Line = function(x,y, w,h, centered, lstyle, fstyle){
	if (lstyle) lineStyle.apply(this, lstyle);
	this.moveTo(x, y);
	this.lineTo(x+w, y+h);
	return this;
};
MovieClip.prototype.SimpleCurve = function(x,y, w,h, centered, lstyle, fstyle){
	if (lstyle) lineStyle.apply(this, lstyle);
	this.moveTo(x, y);
	var cx = x+w, cy = y;
	this.curveTo(cx, cy, x+w, y+h);
	return this;
};