-----------------------------------------------------------------------------------------------------------------
CODES
SEARCH THIS LINE plusRes = parseInt(input1) + parseInt(input2);
https://www.google.co.uk/search?q=plusRes+%3D+parseInt(input1)+%2B+parseInt(input2)%3B&rlz=1C1GNAM_en-GBGB688GB688&oq=plusRes+%3D+parseInt(input1)+%2B+parseInt(input2)%3B&aqs=chrome..69i57.248j0j8&sourceid=chrome&ie=UTF-8
//http://jonnycarlyon.deviantart.com/art/ActionScript-3-Calculator-97711556
//http://forums.mediabox.fr/topic/159117-as3/
//http://theflashstudioblog.blogspot.co.uk/2011/02/actionscript-virtual-keyboard.html
--------------------------------------------------------------------------------------------------------------
CODE NO:1 WITH this. & parseInt
------------------------------------------------------------------------------------------------------------
//http://jonnycarlyon.deviantart.com/art/ActionScript-3-Calculator-97711556
//http://forums.mediabox.fr/topic/159117-as3/
//http://theflashstudioblog.blogspot.co.uk/2011/02/actionscript-virtual-keyboard.html
var subRes:Number;
var div_btn:SimpleButton;
var input1:String;
var mult_btn:SimpleButton;
var plusSym:Boolean;
var multRes:Number;
var sub_btn:SimpleButton;
var divRes:Number;
var equals_btn:SimpleButton;
var subSym:Boolean;
var num1:TextField;
var num2:TextField;
var plusRes:Number;
var input2:String;
var results_txt:TextField;
var plus_btn:SimpleButton;
var sym_txt:TextField;
var divSym:Boolean;
var multSym:Boolean;
this.plusSym = false;
this.subSym = false;
this.multSym = false;
this.divSym = false;
this.num1.border = true;
this.num2.border = true;
//RESTRICT ABC ETC ONLY PUT NUMBERS
this.num1.restrict = "0-9";
this.num2.restrict = "0-9";
//RESTRICT ABC ETC ONLY PUT NUMBERS
this.equals_btn.addEventListener(MouseEvent.CLICK, this.equClick);
function equClick(event:MouseEvent): void{
this.input1 = this.num1.text;
this.input2 = this.num2.text;
if (this.plusSym == true){
this.plusRes = parseInt(this.input1) + parseInt(this.input2);
this.plusRes.toString();
this.results_txt.text = String(this.plusRes);
}
else if (this.subSym == true){
this.subRes = parseInt(this.input1) - parseInt(this.input2);
this.subRes.toString();
this.results_txt.text = String(this.subRes);
}
else if (this.multSym == true){
this.multRes = parseInt(this.input1) * parseInt(this.input2);
this.multRes.toString();
this.results_txt.text = String(this.multRes);
}
else if (this.divSym == true){
this.divRes = parseInt(this.input1) / parseInt(this.input2);
this.divRes.toString();
this.results_txt.text = String(this.divRes);
}
else{
this.results_txt.text = "Please choose an operator (+, -, x, /).";
}
return;
}
this.mult_btn.addEventListener(MouseEvent.CLICK, this.multClick);
function multClick(event:MouseEvent) : void{
this.plusSym = false;
this.subSym = false;
this.multSym = true;
this.divSym = false;
this.sym_txt.text = "x";
return;
}
this.div_btn.addEventListener(MouseEvent.CLICK, this.divClick);
function divClick(event:MouseEvent) : void{
this.plusSym = false;
this.subSym = false;
this.multSym = false;
this.divSym = true;
this.sym_txt.text = "/";
return;
}
this.plus_btn.addEventListener(MouseEvent.CLICK, this.plusClick);
function plusClick(event:MouseEvent) : void{
this.plusSym = true;
this.subSym = false;
this.multSym = false;
this.divSym = false;
this.sym_txt.text = "+";
return;
}
this.sub_btn.addEventListener(MouseEvent.CLICK, this.subClick);
function subClick(event:MouseEvent) : void{
this.plusSym = false;
this.subSym = true;
this.multSym = false;
this.divSym = false;
this.sym_txt.text = "-";
return;
}
--------------------------------------------------------------------------------------------------------------
CODE NO:2 WITHOUT this. & parseInt
------------------------------------------------------------------------------------------------------------
CODE NO:2 WITHOUT this. & parseInt
------------------------------------------------------------------------------------------------------------
var plusRes:Number;
var subRes:Number;
var multRes:Number;
var divRes:Number;
var plusSym:Boolean = false ;
var subSym:Boolean = false;
var multSym:Boolean = false;
var divSym:Boolean = false;
var input1:String;
var input2:String;
var num1:TextField;
var num2:TextField;
num1.border = true;
num2.border = true;
var results_txt:TextField;
var sym_txt:TextField;
var div_btn:SimpleButton;
var mult_btn:SimpleButton;
var sub_btn:SimpleButton;
var equals_btn:SimpleButton;
var plus_btn:SimpleButton;
//RESTRICT ABC ETC ONLY PUT NUMBERS
num1.restrict = "0-9";
num2.restrict = "0-9";
//RESTRICT ABC ETC ONLY PUT NUMBERS
plus_btn.addEventListener(MouseEvent.CLICK, plusClick);
function plusClick(event:MouseEvent) : void{
plusSym = true;
subSym = false;
multSym = false;
divSym = false;
sym_txt.text = "+";
return;
}
sub_btn.addEventListener(MouseEvent.CLICK, subClick);
function subClick(event:MouseEvent): void{
subSym = true;
plusSym = false;
multSym = false;
divSym = false;
sym_txt.text = "-";
return;
}
mult_btn.addEventListener(MouseEvent.CLICK, multClick);
function multClick(event:MouseEvent) : void{
multSym = true;
plusSym = false;
subSym = false;
divSym = false;
sym_txt.text = "x";
return;
}
div_btn.addEventListener(MouseEvent.CLICK, divClick);
function divClick(event:MouseEvent) : void{
divSym = true;
plusSym = false;
subSym = false;
multSym = false;
sym_txt.text = "/";
return;
}
equals_btn.addEventListener(MouseEvent.CLICK, equClick);
function equClick(event:MouseEvent): void{
input1 = num1.text;
input2 = num2.text;
if (plusSym == true){
plusRes = Number(input1) + Number(input2);
plusRes.toString();
results_txt.text = String(plusRes);
}
else if (subSym == true){
subRes = Number(input1) - Number(input2);
subRes.toString();
results_txt.text = String(subRes);
}
else if(multSym == true){
multRes = Number(input1) * Number(input2);
multRes.toString();
results_txt.text = String(multRes);
}
else if (divSym == true){
divRes = Number(input1) / Number(input2);
divRes.toString();
results_txt.text = String(divRes);
}
else{
results_txt.text = "Please choose an operator (+, -, x, /).";
}
return;
}
--------------------------------------------------------------------------------------------------------------
ActionScript Virtual Keyboard Calculator
Part One
This is my first attempt at creating a virtual keyboard calculator. I got the script for the calculations from TUTVID, and added the number pads myself. As you can see below you have to add a different function to every button and direct the button to output to a specific text box.
I placed all the numbers inside movie clips (keyPad and keyPad2). Each keypad is assigned a textfield for output. In the next version I will attempt to use both keypads and textfields with only one visible at a time. Hope this get some of you started on creating your own virtual keyboards.
import flash.text.TextField;
import flash.events.TextEvent;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.events.MouseEvent;
stage.focus = numBox;
addBtn.addEventListener(MouseEvent.CLICK, plusClick);
subBtn.addEventListener(MouseEvent.CLICK, subClick);
mulBtn.addEventListener(MouseEvent.CLICK, multClick);
divBtn.addEventListener(MouseEvent.CLICK, divClick);
equalBtn.addEventListener(MouseEvent.CLICK, equClick);
clearBtn.addEventListener(MouseEvent.CLICK, clearAll);
addBtn.addEventListener(MouseEvent.CLICK, plusClick);
subBtn.addEventListener(MouseEvent.CLICK, subClick);
mulBtn.addEventListener(MouseEvent.CLICK, multClick);
divBtn.addEventListener(MouseEvent.CLICK, divClick);
equalBtn.addEventListener(MouseEvent.CLICK, equClick);
clearBtn.addEventListener(MouseEvent.CLICK, clearAll);
var plusSym:Boolean = false;
var subSym:Boolean = false;
var multSym:Boolean = false;
var divSym:Boolean = false;
numBox.restrict = "0-9";
numBox2.restrict = "0-9";
var subSym:Boolean = false;
var multSym:Boolean = false;
var divSym:Boolean = false;
numBox.restrict = "0-9";
numBox2.restrict = "0-9";
//KEYPAD 1
keyPad.num1.addEventListener(MouseEvent.CLICK, postNum1);
function postNum1(Event:MouseEvent):void{
numBox.text += "1";
}
keyPad.num2.addEventListener(MouseEvent.CLICK, postNum2);
function postNum2(Event:MouseEvent):void{
numBox.text += "2";
}
keyPad.num3.addEventListener(MouseEvent.CLICK, postNum3);
function postNum3(Event:MouseEvent):void{
numBox.text += "3";
}
keyPad.num4.addEventListener(MouseEvent.CLICK, postNum4);
function postNum4(Event:MouseEvent):void{
numBox.text += "4";
}
keyPad.num5.addEventListener(MouseEvent.CLICK, postNum5);
function postNum5(Event:MouseEvent):void{
numBox.text += "5";
}
keyPad.num6.addEventListener(MouseEvent.CLICK, postNum6);
function postNum6(Event:MouseEvent):void{
numBox.text += "6";
}
keyPad.num7.addEventListener(MouseEvent.CLICK, postNum7);
function postNum7(Event:MouseEvent):void{
numBox.text += "7";
}
keyPad.num8.addEventListener(MouseEvent.CLICK, postNum8);
function postNum8(Event:MouseEvent):void{
numBox.text += "8";
}
keyPad.num9.addEventListener(MouseEvent.CLICK, postNum9);
function postNum9(Event:MouseEvent):void{
numBox.text += "9";
}
keyPad.num0.addEventListener(MouseEvent.CLICK, postNum0);
function postNum0(Event:MouseEvent):void{
numBox.text += "0";
}
//KEYPAD 2
keyPad2.num1.addEventListener(MouseEvent.CLICK, postNum21);
function postNum21(Event:MouseEvent):void{
numBox2.text += "1";
}
keyPad2.num2.addEventListener(MouseEvent.CLICK, postNum22);
function postNum22(Event:MouseEvent):void{
numBox2.text += "2";
}
keyPad2.num3.addEventListener(MouseEvent.CLICK, postNum23);
function postNum23(Event:MouseEvent):void{
numBox2.text += "3";
}
keyPad2.num4.addEventListener(MouseEvent.CLICK, postNum24);
function postNum24(Event:MouseEvent):void{
numBox2.text += "4";
}
keyPad2.num5.addEventListener(MouseEvent.CLICK, postNum25);
function postNum25(Event:MouseEvent):void{
numBox2.text += "5";
}
keyPad2.num6.addEventListener(MouseEvent.CLICK, postNum26);
function postNum26(Event:MouseEvent):void{
numBox2.text += "6";
}
keyPad2.num7.addEventListener(MouseEvent.CLICK, postNum27);
function postNum27(Event:MouseEvent):void{
numBox2.text += "7";
}
keyPad2.num8.addEventListener(MouseEvent.CLICK, postNum28);
function postNum28(Event:MouseEvent):void{
numBox2.text += "8";
}
keyPad2.num9.addEventListener(MouseEvent.CLICK, postNum29);
function postNum29(Event:MouseEvent):void{
numBox2.text += "9";
}
keyPad2.num0.addEventListener(MouseEvent.CLICK, postNum20);
function postNum20(Event:MouseEvent):void{
numBox2.text += "0";
}
keyPad.num1.addEventListener(MouseEvent.CLICK, postNum1);
function postNum1(Event:MouseEvent):void{
numBox.text += "1";
}
keyPad.num2.addEventListener(MouseEvent.CLICK, postNum2);
function postNum2(Event:MouseEvent):void{
numBox.text += "2";
}
keyPad.num3.addEventListener(MouseEvent.CLICK, postNum3);
function postNum3(Event:MouseEvent):void{
numBox.text += "3";
}
keyPad.num4.addEventListener(MouseEvent.CLICK, postNum4);
function postNum4(Event:MouseEvent):void{
numBox.text += "4";
}
keyPad.num5.addEventListener(MouseEvent.CLICK, postNum5);
function postNum5(Event:MouseEvent):void{
numBox.text += "5";
}
keyPad.num6.addEventListener(MouseEvent.CLICK, postNum6);
function postNum6(Event:MouseEvent):void{
numBox.text += "6";
}
keyPad.num7.addEventListener(MouseEvent.CLICK, postNum7);
function postNum7(Event:MouseEvent):void{
numBox.text += "7";
}
keyPad.num8.addEventListener(MouseEvent.CLICK, postNum8);
function postNum8(Event:MouseEvent):void{
numBox.text += "8";
}
keyPad.num9.addEventListener(MouseEvent.CLICK, postNum9);
function postNum9(Event:MouseEvent):void{
numBox.text += "9";
}
keyPad.num0.addEventListener(MouseEvent.CLICK, postNum0);
function postNum0(Event:MouseEvent):void{
numBox.text += "0";
}
//KEYPAD 2
keyPad2.num1.addEventListener(MouseEvent.CLICK, postNum21);
function postNum21(Event:MouseEvent):void{
numBox2.text += "1";
}
keyPad2.num2.addEventListener(MouseEvent.CLICK, postNum22);
function postNum22(Event:MouseEvent):void{
numBox2.text += "2";
}
keyPad2.num3.addEventListener(MouseEvent.CLICK, postNum23);
function postNum23(Event:MouseEvent):void{
numBox2.text += "3";
}
keyPad2.num4.addEventListener(MouseEvent.CLICK, postNum24);
function postNum24(Event:MouseEvent):void{
numBox2.text += "4";
}
keyPad2.num5.addEventListener(MouseEvent.CLICK, postNum25);
function postNum25(Event:MouseEvent):void{
numBox2.text += "5";
}
keyPad2.num6.addEventListener(MouseEvent.CLICK, postNum26);
function postNum26(Event:MouseEvent):void{
numBox2.text += "6";
}
keyPad2.num7.addEventListener(MouseEvent.CLICK, postNum27);
function postNum27(Event:MouseEvent):void{
numBox2.text += "7";
}
keyPad2.num8.addEventListener(MouseEvent.CLICK, postNum28);
function postNum28(Event:MouseEvent):void{
numBox2.text += "8";
}
keyPad2.num9.addEventListener(MouseEvent.CLICK, postNum29);
function postNum29(Event:MouseEvent):void{
numBox2.text += "9";
}
keyPad2.num0.addEventListener(MouseEvent.CLICK, postNum20);
function postNum20(Event:MouseEvent):void{
numBox2.text += "0";
}
//CALCULATIONS
function plusClick(event:MouseEvent):void
{
plusSym = true;
subSym = false;
multSym = false;
divSym = false;
symTxt.text = "+";
stage.focus = numBox2;
}
function subClick(event:MouseEvent):void
{
plusSym = false;
subSym = true;
multSym = false;
divSym = false;
symTxt.text = "-";
stage.focus = numBox2;
}
function multClick(event:MouseEvent):void
{
plusSym = false;
subSym = false;
multSym = true;
divSym = false;
symTxt.text = "x";
stage.focus = numBox2;
}
function divClick(event:MouseEvent):void
{
plusSym = false;
subSym = false;
multSym = false;
divSym = true;
symTxt.text = "/";
stage.focus = numBox2;
}
{
plusSym = true;
subSym = false;
multSym = false;
divSym = false;
symTxt.text = "+";
stage.focus = numBox2;
}
function subClick(event:MouseEvent):void
{
plusSym = false;
subSym = true;
multSym = false;
divSym = false;
symTxt.text = "-";
stage.focus = numBox2;
}
function multClick(event:MouseEvent):void
{
plusSym = false;
subSym = false;
multSym = true;
divSym = false;
symTxt.text = "x";
stage.focus = numBox2;
}
function divClick(event:MouseEvent):void
{
plusSym = false;
subSym = false;
multSym = false;
divSym = true;
symTxt.text = "/";
stage.focus = numBox2;
}
var input1:String;
var input2:String;
var plusRes:Number;
var subRes:Number;
var divRes:Number;
var multRes:Number;
var input2:String;
var plusRes:Number;
var subRes:Number;
var divRes:Number;
var multRes:Number;
function equClick(event:MouseEvent):void
{
input1 = numBox.text;
input2 = numBox2.text;
if (plusSym == true)
{
plusRes = parseInt(input1) + parseInt(input2);
plusRes.toString();
resultsTxt.text = String(plusRes);
}
else if (subSym==true)
{
subRes = parseInt(input1) - parseInt(input2);
subRes.toString();
resultsTxt.text = String(subRes);
}
else if (multSym==true)
{
multRes = parseInt(input1) * parseInt(input2);
multRes.toString();
resultsTxt.text = String(multRes);
}
else if (divSym==true)
{
divRes = parseInt(input1) / parseInt(input2);
divRes.toString();
resultsTxt.text = String(divRes);
}
}
function clearAll(event:MouseEvent):void
{
numBox.text = "";
numBox2.text = "";
resultsTxt.text = "";
symTxt.text = "";
stage.focus = numBox;
{
input1 = numBox.text;
input2 = numBox2.text;
if (plusSym == true)
{
plusRes = parseInt(input1) + parseInt(input2);
plusRes.toString();
resultsTxt.text = String(plusRes);
}
else if (subSym==true)
{
subRes = parseInt(input1) - parseInt(input2);
subRes.toString();
resultsTxt.text = String(subRes);
}
else if (multSym==true)
{
multRes = parseInt(input1) * parseInt(input2);
multRes.toString();
resultsTxt.text = String(multRes);
}
else if (divSym==true)
{
divRes = parseInt(input1) / parseInt(input2);
divRes.toString();
resultsTxt.text = String(divRes);
}
}
function clearAll(event:MouseEvent):void
{
numBox.text = "";
numBox2.text = "";
resultsTxt.text = "";
symTxt.text = "";
stage.focus = numBox;
}
EmoticonEmoticon