一个用纯AS写的正态曲线画法
我的这段AS写了不少有用的函数,如画按钮函数,画坐标轴函数,画框架函数.这些函数都有很强的移植性,以后都可以直接拿来用; //================按钮和坐标轴上的文字=====================//mytxt = ["开始", "暂停", "清除", "全屏", "退出", "继续"];
myNum = ["-30", "-20", "-10", "0", "10", "20", "30", "X", "Y"];
//=====画按钮(type不为0时按钮为凸起状态type=0时按钮为凹下状态)=====//
CommandButton = function (mc, t, type) {
c = 0xffffff;//按钮左和上边框颜色
c1 = 0x000000;//按钮右和下边框颜色
mc.createTextField("txt", 700, 12, 1, 27, 18);
if (!type) {
c = 0x000000;
c1 = 0xffffff; //type=0时左和上与右和下边框颜色交换;
mc.createTextField("txt", 700, 13, 2, 27, 18);//按下时文本框向左下移,使字有凹下感觉
}
with (mc) {
moveTo(0, 20);
lineStyle(1, c, 100);
beginFill(0xD1DEE9);
lineTo(0, 0);
lineTo(50, 0);
lineStyle(1, c1, 100);
lineTo(50, 20);
lineTo(0, 20);
endFill();
txt.text = t;
}
};
//===========画框架=============//
display = function (mc, x, y, w, h, txt, corl) {
with (mc) {
moveTo(x, y);
lineStyle(0.5, 0x00000, 100);
beginFill(corl, 40);
lineTo(x w, y);
lineTo(x w, y h);
lineTo(x, y h);
lineTo(x, y);
endFill();
createTextField("name", 300, x 2, y-17, 0, 0);
name.autoSize = "left";
name.selectable = false;
name.border = true;
name.background = true;
name.backgroundColor = 0x798DA6;
name.textColor = 0xffffff;
name.text = txt;
}
};
//========画坐标轴上刻度及数字==============//
dial = function (mc, len, corl, txt, type) {
with (mc) {
moveTo(0, 0);
lineStyle(0.25, corl, 100);
if (type) {//type不为0时刻度坚着画,为0时刻度横着画;
lineTo(0, len);
createTextField("num", 600, -7, len 1, 0, 0);
} else {
lineTo(len, 0);
createTextField("num", 600, len 1, -2, 0, 0);
}
num.autoSize = true;
num.selectable = false;
num.text = txt;
}
};
//========画坐标轴============//
coordinate = function (x, y) {
_root.moveTo(x-215, y);
_root.lineStyle(0.25, 0x00000, 100);
_root.lineTo(x 215, y);
_root.lineTo(x 185, y 5);
_root.moveTo(x 215, y);
_root.lineTo(x 185, y-5);
_root.moveTo(x, y 20);
_root.lineTo(x, y-220);
_root.lineTo(x-5, y-190);
_root.moveTo(x, y-220);
_root.lineTo(x 5, y-190);
for (i=0; i<19; i) {
_root.createEmptyMovieClip("l" i, 510 i);
if (i<13) {
!(i%2) ? dial(_root["l" i], 5, 0xff0000, myNum, 1) : dial(_root["l" i], 3, 0x000000, "", 1);//刻度隔一个为红色,且有数字
_root["l" i]._x = x-198 33*i;
_root["l" i]._y = y;
}
if (i>12) {//同上
!(i%2) ? dial(_root["l" i], 5, 0xff0000, myNum, 0) : dial(_root["l" i], 3, 0x000000, "", 0);
_root["l" i]._x = x;
_root["l" i]._y = y-33*(i-12);
}
}
_root.createTextField("Xt", 250, x 220, y-3, 18, 18);
_root.createTextField("Yt", 260, x, y-230, 18, 18);
Xt.text = myNum;
Xt.selectable = false;
Yt.text = myNum;
Yt.selectable = false;
};
inputBoxs = function (x, y) {
var alpha = ["u =", "0", "o =", "1"];
for (i=0; i<4; i) {
_root.createTextField("v" i, 800 i, x i*35, y, 30, 16);
if (i%2) {
_root["v" i].type = "input";
_root["v" i].border = true;
_root["v" i].text = alpha;
} else {
_root["v" i].autoSize = "right";
_root["v" i].selectable = false;
_root["v" i].text = alpha;
}
}
};
//======写标题========//
headline = function (x, y, txt, dx) {
_root.createTextField("title", 900, x, y, 0, 0);
title.autoSize = true;
title.selectable = false;
title.text = txt;
mytxf = new TextFormat();//创建一个文本格式对象;
mytxf.size = dx;//太小
mytxf.color = 0xff0000;//颜色
mytxf.underline = true;//下划线
title.setTextFormat(mytxf);
};
//=====开始画线函数====//
startDraw = function () {
m = Number(v1.text);
n = Number(v3.text);//把v1,v3文本框中的值给m,n;
x = -200;
_root.createEmptyMovieClip("xian", 300);
xian.moveTo(-200, 100);
xian._x = 275;
xian._y = 193;
_root.onEnterFrame = function() {
a = -(
页:
[1]