I am having trouble getting my calculator working… could someone look at it…
I have been looking at it over and over again…and can not figure out what I did wrong…
I have one mc which is the buttons for the calculator
on that mc… I have code
on (release) {
_parent.keyPressed(this._name);
}
then in the main movie…
have two layers…
numbers
keys… I placed the mc on the stage… then made instances
the code I have on the keys layer…
// start by clearing the display and variables
clearAll();
function clearAll() {
display = “0”; // the visible display
memory = 0; // the buffer
operation = “none”; // what operation is happening
newNum = true; // whether to start a new number
}
// function called by buttons
function keyPressed(keyName) {
// do something different for different keys
switch (keyName) {
case "clear" : // for clear key, start over
clearAll();
break;
case "plus" : // for any operation, go to operate function
operate(keyName);
break;
case "minus" :
operate(keyName);
break;
case "multiply" :
operate(keyName);
break;
case "divide" :
operate(keyName);
break;
case "equals" :
operate(keyName);
break;
default : // all others are added as part of the number
if (newNum) { // new numbers replace the display
display = keyName;
newNum = false;
if (display == "0") newNum = true; // don't allow leading 0s
} else {
display += keyName; // append a digit
}
break;
}
}
// perform operation and prepare for next operation
function operate(keyName) {
switch (operation) {
case “none” : // this is the first number
memory = parseFloat(display); // set memory to that number
break;
case "plus" : // perform operation with memory and new number
memory += parseFloat(display);
break;
case "minus" :
memory -= parseFloat(display);
break;
case "multiply" :
memory *= parseFloat(display);
break;
case "divide" :
memory /= parseFloat(display);
break;
}
// equals operation is like a clear, but results are displayed
if (keyName == "equals") {
operation = "none";
} else {
operation = keyName; // remember this operation for next time
}
display = memory.toString(); // display result
newNum = true; // prepare for next number
}
I would post the fla… but guess it is too big for in here…