# Beginner with flash help with calculator

**URL:** <https://forum.kirupa.com/t/beginner-with-flash-help-with-calculator/256810>\
**Category:** Uncategorized\
**Created:** [April 7, 2008, 3:44pm UTC](https://forum.kirupa.com/t/beginner-with-flash-help-with-calculator/256810 "2008-04-07T15:44:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mushi206](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@mushi206](https://forum.kirupa.com/u/mushi206)\
**Post date:** [April 7, 2008, 3:44pm UTC](https://forum.kirupa.com/t/beginner-with-flash-help-with-calculator/256810/1 "2008-04-07T15:44:08Z")

</div>

Hi im new to flash and am a bit stuck on why my calculator dosnt work properly.

What happens is that when i just have the + coding it works fine.

Thats the same for the - code.

When I put the two together then it only allows on of them either + or - to work and not both.

What i need is both to work and to add code to make \* and / work.

Thanks

Any and all help is appreciated!

Here is the code

//Code for + calculation  
add\_btn.onRelease = function ()  
{  
var number1:Number = Number(input1\_txt.text);  
var number2:Number = Number(input2\_txt.text);  
result\_txt.text = Number1 + Number2  
}

var value1:Number;  
var value2:Number;  
var answer:Number;  
//Values will be + unless letters are entered then message appears  
add\_btn.onRelease = function(){  
readInputs();  
if ( validateInput() ){  
performOperation( “add” );  
displayResult();  
} else {  
result\_txt.text = “You must enter numbers”  
}

}

function readInputs() {  
value1 = Number(input1\_txt.text);  
value2 = Number(input2\_txt.text);  
}  
function validateInput(){

if ( isNaN(value1) || isNaN(value2) ){  
return false;  
} else {  
return true;  
}  
}

function performOperation( op:String ){  
if ( op == “add”) {  
answer = value1 + value2;  
}  
}

function displayResult() {  
result\_txt.text = answer;  
}  
//code for - calculation  
subtract\_btn.onRelease = function ()  
{  
var number1:Number = Number(input1\_txt.text);  
var number2:Number = Number(input2\_txt.text);  
result\_txt.text = Number1 - Number2  
}

var value1:Number;  
var value2:Number;  
var answer:Number;

subtract\_btn.onRelease = function(){  
readInputs();  
if ( validateInput() ){  
performOperation( “subtract” );  
displayResult();  
} else {  
result\_txt.text = “You must enter numbers”  
}

}

function readInputs() {  
value1 = Number(input1\_txt.text);  
value2 = Number(input2\_txt.text);  
}  
function validateInput(){

if ( isNaN(value1) || isNaN(value2) ){  
return false;  
} else {  
return true;  
}  
}

function performOperation( op:String ){  
if ( op == “subtract”) {  
answer = value1 - value2;  
}  
}  
//displays answer  
function displayResult() {  
result\_txt.text = answer;  
}
