1package {
2	import flash.display.*;
3	import flash.geom.*;
4  import flash.events.*;
5  import flash.net.*;
6
7	public class textboxclass extends Sprite {
8		public function textboxclass():void {
9			firstcreate();
10		}
11
12		public function firstcreate():void {
13			//Like clear, only it creates the actual arrays, etc
14			for (iter = 0; iter < 10; iter++) {
15				var t:String = new String;	t = "";
16				line.push(t);
17			}
18			x = 0; y = 0; w = 0; h = 0; numlines = 0; lw = 0; tl = 0; tm = 0; active = false; timer = 0;
19		}
20
21		public function clear():void {
22			//Set all values to a default, required for creating a new entity
23			for (iter = 0; iter < 12; iter++) {
24				line[iter]="";
25			}
26			textrect = new Rectangle();
27			xp = 0; yp = 0; w = 0; h = 0; numlines = 1; lw = 0; tl = 0; tm = 0; active = true; timer = 0;
28		}
29
30		public function centerx():void { resize();	xp = 160 - (w / 2);	resize(); }
31		public function centery():void { resize();	yp = 120 - (h / 2); resize();	}
32
33		public function adjust():void {
34			resize();
35			if (xp < 10) xp = 10;
36			if (yp < 10) yp = 10;
37			if (xp + w > 310) xp = 310 - w;
38			if (yp + h > 230) yp = 230 - h;
39			resize();
40		}
41
42		public function initcol(rr:int, gg:int, bb:int):void {
43			tr = rr; tg = gg; tb = bb;
44			r = 0; g = 0; b = 0; tl = 0.5;
45		}
46
47		public function setcol(rr:int, gg:int, bb:int):void {
48			r = rr; g = gg; b = bb;
49		}
50
51		public function update():void {
52			if (tm == 0) {
53				tl += .1;
54				if (tl >= 1) { tl = 1; tm = 1; }
55				setcol(int(tr * tl), int(tg * tl), int(tb * tl));
56			}else if (tm == 2) {
57				tl -= .1;
58				if (tl <= 0.5) { tl = 0.5; active = false; }
59				setcol(int(tr * tl), int(tg * tl), int(tb * tl));
60			}
61			if (timer > 0) {
62				timer--;
63				if (timer == 0) tm = 2;
64			}
65		}
66
67		public function remove():void {
68			//tm = 2; tl = 1; //Remove mode
69			tm = 2; tl = 0.4; //Remove mode
70		}
71
72		public function removefast():void {
73			tm = 2; tl = 0.4; //Remove mode
74		}
75
76		public function resize():void {
77			//Set the width and height to the correct sizes
78			max = 0;
79			for (iter = 0; iter < numlines; iter++) if (line[iter].length > max) max = line[iter].length;
80
81			lw = max;
82			w = (max +2) * 8;
83			h = (numlines + 2) * 8;
84			textrect.x = xp; textrect.y = yp;	textrect.width = w;	textrect.height = h;
85		}
86
87		public function addline(t:String):void {
88			line[numlines] = t;
89			numlines++;
90			resize();
91			if (numlines >= 12) numlines = 0;
92		}
93
94    //Fundamentals
95		public var line:Array = new Array;
96		public var xp:int, yp:int, lw:int, w:int, h:int, numlines:int;
97		public var r:int, g:int, b:int;
98		public var tr:int, tg:int, tb:int;
99		public var textrect:Rectangle;
100		public var active:Boolean;
101		public var timer:int;
102
103		public var tl:Number, tm:int;
104
105		public var iter:int, max:int;
106	}
107}
108