# Make this drawing board write only on board area?

**URL:** <https://forum.kirupa.com/t/make-this-drawing-board-write-only-on-board-area/111525>\
**Category:** Uncategorized\
**Created:** [May 27, 2004, 9:14pm UTC](https://forum.kirupa.com/t/make-this-drawing-board-write-only-on-board-area/111525 "2004-05-27T21:14:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![z3r0](https://avatars.discourse-cdn.com/v4/letter/z/cdc98d/32.png) [@z3r0](https://forum.kirupa.com/u/z3r0)\
**Post date:** [May 27, 2004, 9:14pm UTC](https://forum.kirupa.com/t/make-this-drawing-board-write-only-on-board-area/111525/1 "2004-05-27T21:14:33Z")

</div>

First of all sorry for the long post…  
I need to make this drawing board (works good) to write ONLY  
in a 450 x 300 px area. Actually if you select the pencil it draws  
as long as you drag but anywhere else on the movie…

You can download the fla in  
[http://www.soccerschool.com.ar/f/drawingBroadmx.zip](http://www.soccerschool.com.ar/f/drawingBroadmx.zip)

This code is attached to frame 1 and the movie has other action  
on the mclip of the board itself:

CODE of mclip:

onClipEvent (load) {  
function setColors() {  
C = new Color(\_root.Panel.bgfc);  
C.setRGB(\_root.frontColor);  
}  
}

* * *

CODE of frame 1:

\_root.P = 0;  
\_root.level = 1000;  
\_root.tmpx = -1;  
\_root.tmpy = -1;  
\_root.count = 0;  
\_root.isMouseDown = false;  
\_root.frontColor = 0x000000;

//default tamaño del pincel  
\_root.pt = 6;  
\_root.tool = “pen”;  
md = new Object();  
mm = new Object();  
mu = new Object();  
actionList = new Array();  
Number.prototype.HEXtoRGB = function() {  
return {rb:this \>\> 16, gb:(this \>\> 8) & 0xff, bb:this & 0xff};  
};  
Color.prototype.blendRGB = function(c1, c2, t) {  
if (arguments.length == 2) {  
t = c2;  
c2 = this.getRGB();  
}  
if (t\<-1) {  
t = -1;  
} else if (t\>1) {  
t = 1;  
}  
if (t\<0) {  
t = 1+t;  
}  
c1 = c1.HEXtoRGB();  
c2 = c2.HEXtoRGB();  
var ct = (c1.rb+(c2.rb-c1.rb)_t) \<\< 16 | (c1.gb+(c2.gb-c1.gb)t) \<\< 8 | (c1.bb+(c2.bb-c1.bb)t);  
this.setRGB(ct);  
return ct;  
};  
md.onMouseDown = function() {  
if (\_root.paintMode) {  
a = new Object();  
a.start = \_root.P;  
actionList.push(a);  
\_root.isMouseDown = true;  
if (\_root.tool == “del”) {  
for (i=0; i\<\_root.P; i++) {  
if (eval(“P”+i).hitTest(\_root.cursor)) {  
eval(“P”+i).removeMovieClip();  
break;  
}  
}  
}  
if (\_root.tool == “sqr”) {  
Paint.duplicateMovieClip(“P”+\_root.P, \_root.level+P);  
eval(“P”+\_root.P).\_x = \_root.\_xmouse;  
eval(“P”+\_root.P).\_y = \_root.\_ymouse;  
}  
if (\_root.tool == “ova”) {  
Paint.duplicateMovieClip(“P”+\_root.P, \_root.level+P);  
eval(“P”+\_root.P).\_x = \_root.\_xmouse;  
eval(“P”+\_root.P).\_y = \_root.\_ymouse;  
}  
if (\_root.tool == “pen”) {  
Paint.duplicateMovieClip(“P”+\_root.P, \_root.level+P);  
eval(“P”+\_root.P).\_x = \_root.\_xmouse;  
eval(“P”+\_root.P).\_y = \_root.\_ymouse;  
eval(“P”+\_root.P).beginFill(\_root.frontColor, 100);  
eval(“P”+\_root.P).drawCircle((\_root.pt/2), 0, 0);  
this.endFill();  
\_root.P++;  
\_root.tmpx = \_root.\_xmouse;  
\_root.tmpy = \_root.\_ymouse;  
}  
if (\_root.tool == “mak”) {  
Paint.duplicateMovieClip(“P”+\_root.P, \_root.level+P);  
eval(“P”+\_root.P).\_x = \_root.\_xmouse;  
eval(“P”+\_root.P).\_y = \_root.\_ymouse;  
eval(“P”+\_root.P).duplicateMovieClip(eval(“P”+\_root.P).\_name+“shadow”, \_root.P+\_root.level-500);  
sn = eval(“P”+\_root.P).\_name;  
eval(“P”+\_root.P).onUnload = function() {  
eval(this.\_name+“shadow”).removeMovieClip();  
};  
eval(sn+“shadow”).beginFill(\_root.frontColor, 10);  
eval(sn+“shadow”).drawCircle((pt), 0, 0);  
eval(sn+“shadow”).endFill();  
eval(“P”+\_root.P).beginFill(\_root.frontColor10, 5);  
eval(“P”+\_root.P).drawCircle((\_root.pt/2), 0, 0);  
this.endFill();  
\_root.P++;  
\_root.tmpx = \_root.\_xmouse;  
\_root.tmpy = \_root.\_ymouse;  
}  
}  
};  
md.onMouseUp = function() {  
if (\_root.isMouseDown == true) {  
\_root.isMouseDown = false;  
if (\_root.tool == “sqr”) {  
\_root.P++;  
}  
if (\_root.tool == “ova”) {  
\_root.P++;  
}  
actionList[actionList.length-1].end = \_root.P;  
}  
\_root.tmpx = -1;  
\_root.tmpy = -1;  
\_root.level += 1000;  
\_root.count = 0;  
};  
mm.onMouseMove = function() {  
\_root.paintMode = !(Panel.hitTest(\_root.\_xmouse, \_root.\_ymouse, true));  
if (\_root.paintMode) {  
 [//Mouse.hide](https://Mouse.hide)();  
\_root.cursor.\_visible = 1;  
if (\_root.tool == “del”) {  
for (i=0; i\<\_root.P && \_root.isMouseDown; i++) {  
if (eval(“P”+i).hitTest(\_root.cursor)) {  
eval(“P”+i).removeMovieClip();  
}  
}  
}  
if (\_root.tool == “sqr”) {  
if (\_root.isMouseDown) {  
sqr = eval(“P”+(\_root.P));  
sqr.clear();  
point = new Object();  
point.x = \_root.\_xmouse;  
point.y = \_root.\_ymouse;  
sqr.globalToLocal(point);  
toX = point.x;  
toY = point.y;  
sqr.beginFill(\_root.frontColor, 100);  
sqr.moveTo(0, 0);  
sqr.lineTo(toX, 0);  
sqr.lineTo(toX, toY);  
sqr.lineTo(0, toY);  
sqr.endFill();  
}  
}  
if (\_root.tool == “ova”) {  
if (\_root.isMouseDown) {  
ova = eval(“P”+(\_root.P));  
ova.clear();  
point = new Object();  
point.x = \_root.\_xmouse;  
point.y = \_root.\_ymouse;  
ova.globalToLocal(point);  
toX = point.x;  
toY = point.y;  
v\_far = Math.abs(0-toY);  
h\_far = Math.abs(0-toX);  
far = Math.sqrt((v\_farv\_far)+(h\_far_h\_far));  
ova.beginFill(\_root.frontColor, 100);  
ova.drawCircle(far, 0, 0);  
ova.endFill();  
}  
}  
if (\_root.tool == “pen”) {  
\_root.count++;  
if (\_root.count%500 == 0) {  
\_root.level += 1000;  
}  
if (\_root.isMouseDown && \_root.count%4 == 0) {  
if (\_root.tmpx != -1 && \_root.tmpy != -1) {  
Paint.duplicateMovieClip(“P”+\_root.P, \_root.level+P);  
eval(“P”+\_root.P).drawLine(\_root.\_xmouse, \_root.\_ymouse, \_root.tmpx, \_root.tmpy, \_root.pt);  
\_root.P++;  
}  
\_root.tmpx = \_root.\_xmouse;  
\_root.tmpy = \_root.\_ymouse;  
}  
}  
if (\_root.tool == “mak”) {  
\_root.count++;  
if (\_root.count%500 == 0) {  
\_root.level += 1000;  
}  
if (\_root.isMouseDown && \_root.count%2 == 0) {  
if (\_root.tmpx != -1 && \_root.tmpy != -1) {  
Paint.duplicateMovieClip(“P”+\_root.P, \_root.level+P);  
eval(“P”+\_root.P).drawNeonLine(\_root.\_xmouse, \_root.\_ymouse, \_root.tmpx, \_root.tmpy, \_root.pt);  
\_root.P++;  
}  
\_root.tmpx = \_root.\_xmouse;  
\_root.tmpy = \_root.\_ymouse;  
}  
}  
} else {  
Mouse.show();  
\_root.cursor.\_visible = 0;  
}  
};  
Mouse.addListener(md);  
Mouse.addListener(mm);  
Mouse.addListener(mu);  
//  
MovieClip.prototype.drawCircle = function(r, x, y) {  
this.moveTo(x+r, y);  
a = Math.tan(22.5_Math.PI/180);  
for (var angle = 45; angle\<=360; angle += 45) {  
// endpoint:  
var endx = r_Math.cos(angle_Math.PI/180);  
var endy = r_Math.sin(angle_Math.PI/180);  
// control:  
// (angle-90 is used to give the correct sign)  
var cx = endx+r_a_Math.cos((angle-90)Math.PI/180);  
var cy = endy+ra_Math.sin((angle-90)_Math.PI/180);  
this.curveTo(cx+x, cy+y, endx+x, endy+y);  
}  
};  
MovieClip.prototype.drawLine = function(fromX, fromY, toX, toY, pt) {  
this.\_x = fromX;  
this.\_y = fromY;  
point = new Object();  
point.x = toX;  
point.y = toY;  
this.globalToLocal(point);  
// trace(point.x + " " + point.y);  
toX = point.x;  
toY = point.y;  
// way cal  
v\_far = Math.abs(0-toY);  
h\_far = Math.abs(0-toX);  
far = Math.sqrt((v\_far_v\_far)+(h\_far_h\_far));  
adj = (toX-0);  
Q = Math.acos(adj/far)/(Math.PI/180);  
if (0\>toY) {  
rot = 90-Q;  
} else {  
rot = 90+Q;  
}  
if (rot\>90) {  
way = 360-Math.abs(rot-90);  
} else {  
way = Math.abs(rot-90);  
}  
for (i=0; i\<far; i += 2) {  
nx = int((i)Math.cos((way)(Math.PI/180)));  
ny = -(int((i)Math.sin((way)(Math.PI/180))));  
this.beginFill(\_root.frontColor, 100);  
this.drawCircle((pt/2), nx, ny);  
this.endFill();  
}  
};  
MovieClip.prototype.drawNeonLine = function(fromX, fromY, toX, toY, pt) {  
this.\_x = fromX;  
this.\_y = fromY;  
point = new Object();  
point.x = toX;  
point.y = toY;  
this.globalToLocal(point);  
// trace(point.x + " " + point.y);  
toX = point.x;  
toY = point.y;  
// way cal  
v\_far = Math.abs(0-toY);  
h\_far = Math.abs(0-toX);  
far = Math.sqrt((v\_far_v\_far)+(h\_far\*h\_far));  
adj = (toX-0);  
Q = Math.acos(adj/far)/(Math.PI/180);  
if (0\>toY) {  
rot = 90-Q;  
} else {  
rot = 90+Q;  
}  
if (rot\>90) {  
way = 360-Math.abs(rot-90);  
} else {  
way = Math.abs(rot-90);  
}  
this.duplicateMovieClip(this.\_name+“shadow”, \_root.P+\_root.level-500);  
this.onUnload = function() {  
eval(this.\_name+“shadow”).removeMovieClip();  
};  
for (i=0; i\<far; i += 2) {  
nx = int((i)_Math.cos((way)_(Math.PI/180)));  
ny = -(int((i)_Math.sin((way)_(Math.PI/180))));  
eval(this.\_name+“shadow”).beginFill(\_root.frontColor, 10);  
eval(this.\_name+“shadow”).drawCircle((pt), nx, ny);  
eval(+this.\_name+“shadow”).endFill();  
}  
for (i=0; i\<far; i += 2) {  
nx = int((i)_Math.cos((way)_(Math.PI/180)));  
ny = -(int((i)_Math.sin((way)_(Math.PI/180))));  
c = new Color(this);  
c.setRGB(\_root.frontColor);  
c.blendRGB(0xffffff, .2);  
this.beginFill(c.getRGB(), 100);  
this.drawCircle((pt/2), nx, ny);  
this.endFill();  
}  
};  
function cursorReflesh() {  
this.createEmptyMovieClip(“cursor”, 100001);  
c = new Color(this.cursor);  
c.setRGB(\_root.frontColor);  
if (\_root.frontColor\>(0xffffff/2)) {  
c.blendRGB(0x000000, -0.3);  
} else {  
c.blendRGB(0xffffff, -0.5);  
}  
this.cursor.lineStyle(1, 0xffffff, 100);  
this.cursor.drawCircle(pt/2, 0, 0);  
this.cursor.startDrag(true);  
}  
function undo() {  
if (actionList.length\>0) {  
a = actionList.pop();  
if (a.start == undefined) {  
C = new Color(this.Background);  
C.setRGB(a);  
C2 = new Color(this.Panel.bubg);  
C2.setRGB(a);  
} else {  
for (i=a.start; i\<=a.end; i++) {  
eval(“P”+i).removeMovieClip();  
}  
\_root.P = a.start;  
}  
}  
}  
cursorReflesh();
