flash计算器的制作[下]
6、在各个按扭上分别加as:
(1)、按扭M+:
on (release) {
memory = memory+Number(display);
symbol = "";
mem = "M+";
}
其中变量memory是用来保存记忆的结果的。
(2)、按扭MR
on (release) {
display = memory;
//memory = 0;
//symbol = " ";
//clear = true;
}
其中clear标识,显示十分清空状态变量
(3)、按扭MC
on (release) {
memory = 0;
mem = " ";
display = "0";
operator = "";
operand = false;
clear = false;
decimal = false;
}
(4)、按扭%
on (release, keyPress "%") {
display = display*operand/100;
}
变量operand是操作数变量。
(5)、按扭C
on (press, keyPress "c") {
display = "0";
operator = "";
symbol = "";
operand = false;
clear = true;
decimal = false;
}
on (press, keyPress "C") {
display = "0";
operator = "";
symbol = "";
operand = false;
clear = true;
decimal = false;
}
变量decimal 是标识是否是小数
(6)、按扭1
on (release, keyPress "1") {
getdigit("1");
}
(7)、按扭2
on (release, keyPress "2") {
getdigit("2");
}
(8)、按扭3
on (release, keyPress "3") {
getdigit("3");
}
(9)、按扭4
on (release, keyPress "4") {
getdigit("4");
}
(10)、按扭5
on (release, keyPress "5") {
getdigit("5");
}
(11)、按扭6
on (release, keyPress "6") {
getdigit("6");
}
(12)、按扭7
on (release, keyPress "7") {
getdigit("7");
}
(13)、按扭8
on (release, keyPress "8") {
getdigit("8");
}
(14)、按扭9
on (release, keyPress "9") {
getdigit("9");
}
(15)、按扭0
on (release, keyPress "0") {
getdigit("0");
}
(16)、按扭.
on (release, keyPress ".") {
if (!decimal) {
getdigit(".");
decimal = true;
}
}
(17)、按扭=
on (release, keyPress "") {
getoperator();
}
(18)、按扭+
on (release, keyPress "+") {
getoperator("+");
}
(19)、按扭-
on (release, keyPress "-") {
getoperator("-");
}
(20)、按扭×
on (release, keyPress "*") {
getoperator("*");
}
(21)、按扭/
on (release, keyPress "/") {
getoperator("/");
}
测试运算看看是否正确,这个计算器的关键在函数getoperator(),完成了计算和显示功能。其中用到了系统函数Number(),其作用就是把其他类型的数据全部按照一定的规则转化为数字类型。