How to: Copy the code to the frame to see the effect
effect: You can press and hold the mouse to draw the line, can be used as a simple duck-painting tools
http://www.flash8.net/bbs/UploadFile/2005-7/2005721365810.swf
Code: Createemptymovieclip ("Xian", 1);
With (Xian) {
_root.onmousemove = function () {
if (draw) {
_root.linestyle (0, 0x000000, 100);
_root.lineto (_root._xmouse, _root._ymouse);
}
};
_root.onmousedown = function () {
Draw = true;
_root.moveto (_root._xmouse, _root._ymouse);
};
_root.onmouseup = function () {
Draw = false;
};
}
Draw a line with the mouse any
Effect: A line tool similar to flash
Code:
Createemptymovieclip ("line", N);
With (line) {
LineStyle (1, 0x000000, 100);
MoveTo (0, 0);
LineTo (100, 100);
line._visible = 0;
}
_root.onmousedown = function () {
qidian_x = _root._xmouse;
qidian_y = _root._ymouse;
With (line) {
_x = qidian_x;
_y = qidian_y;
_xscale = 0;
_yscale = 0;
_visible = 1;
}
};
_root.onmousemove = function () {
EndX = _root._xmouse;
EndY = _root._ymouse;
if (_root.line!= "_root.line" && Key.isdown (16)) {
if (Math.Abs (endx-qidian_x) >math.abs (endy-qidian_y)) {
SetProperty (_root.line, _xscale, endx-qidian_x);
SetProperty (_root.line, _yscale, endx-qidian_x);
} else {
SetProperty (_root.line, _xscale, endy-qidian_y);
SetProperty (_root.line, _yscale, endy-qidian_y);
}
} else {
SetProperty (_root.line, _xscale, endx-qidian_x);
SetProperty (_root.line, _yscale, endy-qidian_y);
}
};
_root.onmouseup = function () {
if (_root._xmouse-qidian_x!= 0) {
i++;
Objectx = "Copy" Add I;
Duplicatemovieclip (_root.line, Objectx, i);
SetProperty (Objectx, _x, qidian_x);
SetProperty (Objectx, _y, qidian_y);
_ROOT.I = i;
}
SetProperty (_root.line, _visible, 0);
};
Draw a rectangle with any mouse
Effect: A rectangular tool similar to flash
Code:
Createemptymovieclip ("line", N);
With (line) {
LineStyle (0.1, 0x000000, 100);
MoveTo (0, 0);
LineTo (100, 0);
LineTo (100, 100);
LineTo (0, 100);
LineTo (0,0);
line._visible = 0;
}
_root.onmousedown = function () {
qidian_x = _root._xmouse;
qidian_y = _root._ymouse;
With (line) {
_x = qidian_x;
_y = qidian_y;
_xscale = 0;
_yscale = 0;
_visible = 1;
}
};
_root.onmousemove = function () {
EndX = _root._xmouse;
EndY = _root._ymouse;
if (_root.line!= "_root.line" && Key.isdown (16)) {
if (Math.Abs (endx-qidian_x) >math.abs (endy-qidian_y)) {
SetProperty (_root.line, _xscale, endx-qidian_x);
SetProperty (_root.line, _yscale, endx-qidian_x);
} else {
SetProperty (_root.line, _xscale, endy-qidian_y);
SetProperty (_root.line, _yscale, endy-qidian_y);
}
} else {
SetProperty (_root.line, _xscale, endx-qidian_x);
SetProperty (_root.line, _yscale, endy-qidian_y);
}
};
_root.onmouseup = function () {
if (_root._xmouse-qidian_x!= 0) {
i++;
Objectx = "Copy" Add I;
Duplicatemovieclip (_root.line, Objectx, i);
SetProperty (Objectx, _x, qidian_x);
SetProperty (Objectx, _y, qidian_y);
_ROOT.I = i;
}
SetProperty (_root.line, _visible, 0);
};
Use the mouse to draw a circle, Oval
Effects: Similar to the tools in Flash
Code:
Createemptymovieclip ("line", N);
With (line) {
For (n=1 n<400; n++) {
A = 50*math.cos (n*math.pi/180);
b = 50*math.sin (n*math.pi/180);
c = 50*math.cos ((n+1) *math.pi/180);
D = 50*math.sin ((n+1) *math.pi/180);
LineStyle (0.01, 0x000000, 50);
MoveTo (a+50, b+50);
LineTo (c+50, d+50);
}
line._visible = 0;
}
_root.onmousedown = function () {
qidian_x = _root._xmouse;
qidian_y = _root._ymouse;
With (line) {
_x = qidian_x;
_y = qidian_y;
_xscale = 0;
_yscale = 0;
_visible = 1;
}
};
_root.onmousemove = function () {
EndX = _root._xmouse;
EndY = _root._ymouse;
if (_root.line!= "_root.line" && Key.isdown (16)) {
if (Math.Abs (endx-qidian_x) >math.abs (endy-qidian_y)) {
SetProperty (_root.line, _xscale, endx-qidian_x);
SetProperty (_root.line, _yscale, endx-qidian_x);
} else {
SetProperty (_root.line, _xscale, endy-qidian_y);
SetProperty (_root.line, _yscale, endy-qidian_y);
}
} else {
SetProperty (_root.line, _xscale, endx-qidian_x);
SetProperty (_root.line, _yscale, endy-qidian_y);
}
};
_root.onmouseup = function () {
if (_root._xmouse-qidian_x!= 0) {
i++;
Objectx = "Copy" Add I;
Duplicatemovieclip (_root.line, Objectx, i);
SetProperty (Objectx, _x, qidian_x);
SetProperty (Objectx, _y, qidian_y);
_ROOT.I = i;
}
SetProperty (_root.line, _visible, 0);
};
Dotted line with two fixed points
Code: MovieClip.prototype.dashTo = function (StartPoint, Destpoint, Dashlength, spacelength) {
var x = destpoint.x-startpoint.x;
var y = destpoint.y-startpoint.y;
var hyp = math.sqrt ((x) * (x) + (y) * (y));
var units = hyp/(dashlength+spacelength);
var dashspaceratio = dashlength/(dashlength+spacelength);
var dashx = (x/units) *dashspaceratio;
var SpaceX = (x/units)-dashx;
var dashy = (y/units) *dashspaceratio;
var SpaceY = (y/units)-dashy;
This.moveto (Startpoint.x, STARTPOINT.Y);
while (hyp>0) {
Startpoint.x + = Dashx;
Startpoint.y + = dashy;
Hyp-= dashlength;
if (hyp<0) {
Startpoint.x = Destpoint.x;
Startpoint.y = Destpoint.y;
}
This.lineto (Startpoint.x, STARTPOINT.Y);
Startpoint.x + = SpaceX;
Startpoint.y + = SpaceY;
This.moveto (Startpoint.x, STARTPOINT.Y);
Hyp-= spacelength;
}
This.moveto (Destpoint.x, DESTPOINT.Y);
};
Createemptymovieclip ("Drawingspace", 1);
With (Drawingspace) {
LineStyle (0, 0x000000, 100);
Dashto ({x:300, y:0}, {x:0, y:400}, 3, 10);
}
Draw a dashed line from one point to another
Code:
function Drawdottedline (TARGETMC, LineWidth, FromX, FromY, ToX, ToY) {
TARGETMC: Target MovieClip de instancename;
LineWidth: line width;
FromX, FromY: Start painting from (FromX, FromY);
ToX, ToY: Draw to (ToX, ToY) place;
var x, y;
Eval (TARGETMC). LineStyle (LineWidth, 0x000000, 100);
The color of the line is black (0x000000)
Eval (TARGETMC). MoveTo (FromX, FromY);
x = FromX;
y = FromY;
while (xx = x+4/(math.sqrt (toy-fromy) * (toy-fromy) + (TOX-FROMX) * (TOX-FROMX)) * (TOX-FROMX);
y = y+4/(math.sqrt (toy-fromy) * (toy-fromy) + (TOX-FROMX) * (TOX-FROMX))) * (toy-fromy);
Eval (TARGETMC). LineTo (x, y);
x = x+4/(MATH.SQRT (toy-fromy) * (toy-fromy) + (TOX-FROMX) * (TOX-FROMX))) * (TOX-FROMX);
y = y+4/(math.sqrt (toy-fromy) * (toy-fromy) + (TOX-FROMX) * (TOX-FROMX))) * (toy-fromy);
Eval (TARGETMC). MoveTo (x, y);
}
}
Createemptymovieclip ("obj", 1);//Build an empty film
Drawdottedline ("_root.obj", 1, 10, 10, 200, 300);//Call function
Draw a dashed line from the top left corner of the scene to the mouse
x = 0;
y = the coordinates of the upper-left corner of the 0;//scene
L = 0;
mx = _root._xmouse;
my = _root._ymouse;//mouse coordinates
ml = math.sqrt (mx*mx+my*my);//Triangle's hypotenuse length
_root.moveto (0, 0);//The starting point of the drawing line is the coordinates of the upper-left corner of the scene
_root.linestyle (0.1, 0x000000, 100);
The following trigonometric functions are used to find the endpoint coordinates of each dashed line, and a short line and a space are repeatedly drawn with loops. Until the end of the line position.
while (LL = 5;
The length of a short dash
x = l*mx/ml;
y = l*my/ml;
_root.lineto (x, y);
Moves the drawing point to the same length as the stub and to the same line as the stub. That is, a space
L + + 5;
x = l*mx/ml;
y = l*my/ml;
_root.moveto (x, y);
}
Nice line function, custom point, line style, padding
function Shape () {
This.points = [];
This.lines = false;
this.filled = false;
This.linestyle = null;
THIS.T = eval (_target);
}
Shape.prototype.addPoint = function (x, y) {
This.points[this.points.length] = {x:x, y:y};
};
Shape.prototype.removePoint = function () {
This.points.pop ();
};
Shape.prototype.draw = function (W, c, a) {
if (this.points.length>1) {
This.linestyle = {w:w, c:c, a:a};
This.t.linestyle (W, C, a);
var i = 0;
var L = this.points.length;
while (Ithis.t.lineto (this.points[i].x, THIS.POINTS[I].Y);
++i;
}
This.lines = true;
}
};
Shape.prototype.fill = function (c, a) {
if (this.points.length>1) {
if (this.lines) {
This.clear ();
This.t.linestyle (THIS.LINESTYLE.W, this.linestyle.c, THIS.LINESTYLE.A);
} else {
This.t.linestyle (0, 0xFFFFFF, 0);
if (this.filled) {
This.clear ();
}
}
This.t.beginfill (c, a);
var i = 0;
var L = this.points.length;
while (Ithis.t.lineto (this.points[i].x, THIS.POINTS[I].Y);
++i;
}
This.t.endfill ();
This.filled = true;
}
};
Shape.prototype.getX = function () {
if (this.points.length) {
return this.points[this.points.length-1].x;
}
};
Shape.prototype.getY = function () {
if (this.points.length) {
return this.points[this.points.length-1].y;
}
};
g = new Shape ();
G.addpoint (0, 100);
G.addpoint (100, 100);
G.addpoint (100, 0);
G.addpoint (0, 0);
G.fill (0x339900, 100);
G.draw (5, 0x000000, 100);