------------------------------------------------------------------------------------------------------------------------------------ STRING CALCULATOR AS3 http://flashcollege.blogspot.co.uk/2016/05/boolean-calculator-as3_16.html
https://www.youtube.com/watch?v=zNZzC4iTSkI ------------------------------------------------------------------------------------------------------------------------------------ num1.restrict = "0-9"; num2.restrict = "0-9"; //MAKE EMPTY STRING var NumString:String = ""; //MAKE EMPTY STRING plus_btn.addEventListener(MouseEvent.CLICK, plusClick); function plusClick(event:MouseEvent) : void{ NumString = "PLUS"; sym_txt.text = NumString; } sub_btn.addEventListener(MouseEvent.CLICK, subClick); function subClick(event:MouseEvent): void{ NumString = "MINUS"; sym_txt.text = NumString; } mult_btn.addEventListener(MouseEvent.CLICK, multClick); function multClick(event:MouseEvent) : void{ NumString = "MULTIPLY"; sym_txt.text = NumString; } div_btn.addEventListener(MouseEvent.CLICK, divClick); function divClick(event:MouseEvent) : void{ NumString = "DEVIDE"; sym_txt.text = NumString; } equals_btn.addEventListener(MouseEvent.CLICK, equClick); function equClick(event:MouseEvent): void{ var input1:Number= num1.text; var input2:Number= num2.text; if (NumString=="PLUS"){ plusRes = Number(input1) + Number(input2); plusRes.toString(); results_txt.text = String(plusRes); } else if (NumString=="MINUS"){ subRes = Number(input1) - Number(input2); subRes.toString(); results_txt.text = String(subRes); } else if(NumString=="MULTIPLY"){ multRes = Number(input1) * Number(input2); multRes.toString(); results_txt.text = String(multRes); } else if (NumString == "DEVIDE"){ divRes = Number(input1) / Number(input2); divRes.toString(); results_txt.text = String(divRes); } else{ results_txt.text = "Please choose an operator (+, -, x, /)."; } return; } ------------------------------------------------------------------------------------------------------------------------------------ CODE:2 ------------------------------------------------------------------------------------------------------------------------------------ num1.restrict = "0-9"; num2.restrict = "0-9"; //MAKE EMPTY STRING var NumString:String = ""; //MAKE EMPTY STRING plus_btn.addEventListener(MouseEvent.CLICK, plusClick); function plusClick(event:MouseEvent) : void{ NumString = "PLUS"; sym_txt.text = NumString; } sub_btn.addEventListener(MouseEvent.CLICK, subClick); function subClick(event:MouseEvent): void{ NumString = "MINUS"; sym_txt.text = NumString; } mult_btn.addEventListener(MouseEvent.CLICK, multClick); function multClick(event:MouseEvent) : void{ NumString = "MULTIPLY"; sym_txt.text = NumString; } div_btn.addEventListener(MouseEvent.CLICK, divClick); function divClick(event:MouseEvent) : void{ NumString = "DEVIDE"; sym_txt.text = NumString; } equals_btn.addEventListener(MouseEvent.CLICK, equClick); function equClick(event:MouseEvent): void{ var input1:Number= num1.text; var input2:Number= num2.text; if (NumString=="PLUS"){ plusRes = Number(input1) + Number(input2); results_txt.text = plusRes.toString(); } else if (NumString=="MINUS"){ subRes = Number(input1) - Number(input2); results_txt.text = subRes.toString(); } else if(NumString=="MULTIPLY"){ multRes = Number(input1) * Number(input2); results_txt.text = multRes.toString(); } else if (NumString == "DEVIDE"){ divRes = Number(input1) / Number(input2); results_txt.text = divRes.toString(); } else{ results_txt.text = "Please choose an operator (+, -, x, /)."; } return; }
EmoticonEmoticon