Monday, 9 May 2016

PLUS DIVIDE CALCULATOR AS2

PLUS DIVIDE CALCULATOR

------------------------------------------------------------------------------------------------------------
CODE:1
-------------------------------------------------------------------------------------------------------------
//AS2 CALCULATOR
//PASTE Total IN TEXT BOX VARIABLE BOX
Total = "";
Calculator = "AS2";
Btn4.onPress=function(){
Total = "" +Total+4;
}
Btn5.onPress=function(){
Total = "" +Total+5;
}
BtnPlus.onPress=function(){
Num1 = Total * 1;
Calculator = "PlusStage";
Total = "";
}
BtnDivide.onPress=function(){
Num1 = Total * 1;
Calculator = "DivideStage";
Total = "";
}
BtnEqual.onPress=function(){
Num2 = Total * 1;
if(Calculator=="PlusStage"){
Total = Num1 * 1 + Num2 * 1;
}
if(Calculator=="DivideStage"){
Total = Num1 / Num2 ;
}
Calculator = "AS2";
}
------------------------------------------------------------------------------------------------------------
CODE:2
-------------------------------------------------------------------------------------------------------------
//AS2 CALCULATOR
//PASTE Total IN TEXT BOX VARIABLE BOX
Total = "";
Calculator = "AS2";
Btn4.onPress=function(){
Total = "" +Total+4;
}
Btn5.onPress=function(){
Total = "" +Total+5;
}
BtnPlus.onPress=function(){
Num1 = Total * 1;
Calculator = "PlusStage";
Total = "";
}
BtnDivide.onPress=function(){
Num1 = Total * 1;
Calculator = "DivideStage";
Total = "";
}
BtnEqual.onPress=function(){
Num2 = Total * 1;
if(Calculator=="PlusStage"){
Total = Num1 * 1 + Num2 * 1;
}
if(Calculator=="DivideStage"){
Total = Num1 / Num2 ;
}
}
------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------
MAKE 5 BUTTON WITH INSTANCE NAMES
USE TEXT BOX  VARIABLE BOX TYPE "Total"
MAKE STRING NUMBER  TO USE IF CONDITION OR
SWITCH CASE 
CODE:
------------------------------------------------------------------------------------------------------------

//MAKE 5 BUTTONS WITH INSTANCE NAMES
//USE VARIBLE BOX TYPE "Total"
Total = "";
Btn4.onPress=function(){
Total = "" +Total+4;
}
Btn5.onPress=function(){
Total = "" +Total+5;
}
//MAKE STRING NUMBER TO USE DIFFERENT FUNCTION LIKE SWITCH CASE
var NumString:String = "";
BtnPlus.onPress=function(){
Num1 = Total * 1;
Total = "";
NumString = "PLUS";
}
BtnDivide.onPress=function(){
Num1 = Total * 1;
Total = "";
NumString = "DIVIDE";
}
BtnEqual.onPress=function(){
Num2 = Total * 1;
if(NumString=="PLUS"){
Total = Num1 * 1 + Num2 * 1;
}
if(NumString=="DIVIDE"){
Total = Num1 / Num2 ;
}
}
--------------------------------------------------------------------------------------------------------
WITHOUT TYPE VARIABLE IN BOX
--------------------------------------------------------------------------------------------------------
WITHOUT TYPE VARIABLE IN BOX

--------------------------------------------------------------------------------------------------------
CODE:
1) NEED FIVE BUTTONS WITH INSTANCE NAMES: 
Btn1,Btn2,BtnPlus,BtnDivide,BtnEqual
1) NEED TEXT BOX WITH INSTANCE NAME: 
Txt1
--------------------------------------------------------------------------------------------------------

//AS2 CALCULATOR
//NO NEED TO TYPE VARIABLE IN VARIABLE BOX
Txt1.text = "";
Calculator = "AS2";
Btn1.onPress=function(){
Txt1.text = "" +Txt1.text+1;
}
Btn2.onPress=function(){
Txt1.text = "" +Txt1.text+2;
}
BtnPlus.onPress=function(){
Num1 = Txt1.text * 1;
Calculator = "PlusStage";
Txt1.text = "";
}
BtnDivide.onPress=function(){
Num1 = Txt1.text * 1;
Calculator = "DivideStage";
Txt1.text = "";
}
BtnEqual.onPress=function(){
Num2 = Txt1.text * 1;
if(Calculator=="PlusStage"){
Txt1.text = Num1 * 1 + Num2 * 1;
}
if(Calculator=="DivideStage"){
Txt1.text = Num1 / Num2 ;
}
Calculator = "AS2";
}
--------------------------------------------------------------------------------------------------------
EMPTY STRING  CALCULATOR AS2
--------------------------------------------------------------------------------------------------------
Txt1.text = "";
Btn1.onPress=function(){
Txt1.text = "" +Txt1.text+1;
}
Btn2.onPress=function(){
Txt1.text = "" +Txt1.text+2;
}
//MAKE EMPTY STRING FOR MULTIPLE FUNCTION
var EmptyString:String = "";
BtnPlus.onPress=function(){
Num1 = Txt1.text * 1;
EmptyString = "PlusStage";
Txt1.text = "";
}
BtnDivide.onPress=function(){
Num1 = Txt1.text * 1;
EmptyString = "DivideStage";
Txt1.text = "";
}
BtnEqual.onPress=function(){
Num2 = Txt1.text * 1;
if(EmptyString=="PlusStage"){
Txt1.text = Num1 * 1 + Num2 * 1;
}
if(EmptyString=="DivideStage"){
Txt1.text = Num1 / Num2 ;
}
}

--------------------------------------------------------------------------------------------------------
SWITCH CASE  CALCULATOR AS2
--------------------------------------------------------------------------------------------------------
Txt1.text = "";
Btn1.onPress=function(){
Txt1.text = "" +Txt1.text+1;
}
Btn2.onPress=function(){
Txt1.text = "" +Txt1.text+2;
}
//MAKE EMPTY STRING FOR MULTIPLE FUNCTION
var EmptyString:String = "";
BtnPlus.onPress=function(){
Num1 = Txt1.text * 1;
EmptyString = "PlusStage";
Txt1.text = "";
}
BtnDivide.onPress=function(){
Num1 = Txt1.text * 1;
EmptyString = "DivideStage";
Txt1.text = "";
}
BtnEqual.onPress=function(){
Num2 = Txt1.text * 1;
switch(EmptyString){
case "PlusStage" :
Txt1.text = Num1 * 1 + Num2 * 1;
break;
case "DivideStage" :
Txt1.text = Num1 / Num2 ;
break;
}
}
--------------------------------------------------------------------------------------------------------
MULTI TEXT LINE IN SHOW IN TEXT BOX AS2
OR  SCROLL TEXT AS2
https://www.youtube.com/watch?v=cAFoKD00PP0
http://flashcollege.blogspot.co.uk/2016/05/scientific-calculator-as2.html
--------------------------------------------------------------------------------------------------------
STEP 1: MAKE BUTTON WITH INSIDE CODE
STEP 2: MAKE TEXT BOX WITH INSTANCE NAME : aff
--------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------
CODES:
--------------------------------------------------------------------------------------------------------
//AS2 MAIN TIME LINE FRAME NO:1 CODE
function initialize(){
aff.htmlText = "";
brackets.gotoAndStop(1);
enCours = "";
avant = "";
stockEnCours = "";
justResolved = false;
changeShift(false);
formatParentheses = true;
tabLongueurs = new Array();
deg = false;
ans = "";
}
function addSomething(quoi, op){
enCours = enCours + quoi;
tabLongueurs.push(String(quoi).length);
stockEnCours = "<p align=\'left\'>" + enCours + "</p>";
justResolved = false;
updateScreen();
}
function updateScreen(){
formatParentheses = checkBrackets(enCours);
brackets.gotoAndStop(formatParentheses ? (1) : (2));
aff.htmlText = avant + "<p align=\'left\'>" + enCours + "</p>";
aff.scroll = aff.maxscroll;
}
initialize();

// AS2 BUTTON INSIDE CODE:
//IT ALSO WORK WITH COMPUTER KEY PRESS
on(release,keyPress"1"){
addSomething(1);
}

--------------------------------------------------------------------------------------------------------
RANDOM NUMBER SHOW IN TEXT BOX AS2
--------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------
CODES
--------------------------------------------------------------------------------------------------------

//AS2 MAIN TIME LINE FRAME NO:1 CODE
Txt1.htmlText = "";
StrNum1 = "";
tabLongueurs = new Array();
function addSomething(){
StrNum1 = StrNum1 + tabLongueurs;
tabLongueurs.push(String(tabLongueurs).length);
Txt1.htmlText =  StrNum1
Txt1.scroll = Txt1.maxscroll;
}
addSomething();

// AS2 BUTTON INSIDE CODE:
//IT ALSO WORK WITH COMPUTER KEY PRESS
//ADD FUNCTION TAIL PART UNDER BUTTON CODE
on(release,keyPress"1"){
addSomething(1);
}

--------------------------------------------------------------------------------------------------------
SHOW SAME NUMBER IN  TEXT BOX AS2
--------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------
CODES:
--------------------------------------------------------------------------------------------------------
//AS2 MAIN TIME LINE FRAME NO:1 CODE
Txt1.htmlText = "";
StrNum1 = "";
ArrNum1 = new Array();
function addSomething(ONE){
StrNum1 = StrNum1 + ONE;
ArrNum1.push(String(ONE).length);
Txt1.htmlText =  StrNum1
Txt1.scroll = Txt1.maxscroll;
}

// AS2 BUTTON INSIDE CODE:
//IT ALSO WORK WITH COMPUTER KEY PRESS
//ADD FUNCTION TAIL PART UNDER BUTTON CODE
on(release,keyPress"1"){
addSomething(1);
}

------------------------------------------------------------------------------------------------------------
SHOW SAME NUMBER IN  TEXT BOX AS2
OR USE THIS CODE
-------------------------------------------------------------------------------------------------------------
// AS2 BUTTON INSIDE CODE:
//IT ALSO WORK WITH COMPUTER KEY PRESS
//ADD FUNCTION TAIL PART UNDER BUTTON CODE
on(release,keyPress"1"){
Txt1.text = "" +Txt1.text+1;
Txt1.htmlText = Txt1.text
Txt1.scroll = Txt1.text.maxscroll;
}




EmoticonEmoticon