Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- import fl.controls.Button;
- public class CalcMain extends Sprite {
- private var sum:int;
- private var tall1:int = 0;
- private var tall2:int = 0;
- private var tekstFelt:TextField;
- private var equals:Button;
- private var button1:Button;
- private var button2:Button;
- private var button3:Button;
- private var button4:Button;
- private var button5:Button;
- private var button6:Button;
- private var button7:Button;
- private var button8:Button;
- private var button9:Button;
- private var resetButton:Button;
- private var kalkBack:LkalkBack;
- private var tekstBack:LtekstBack;
- public function CalcMain()
- {
- kalkBack = new LkalkBack;
- kalkBack.x = 75;
- kalkBack.y = 225;
- addChild(kalkBack);
- tekstBack = new LtekstBack;
- tekstBack.x = 55;
- tekstBack.y = 178;
- tekstBack.width = 80;
- tekstBack.height = 20;
- addChild(tekstBack);
- tekstFelt = new TextField();
- tekstFelt.x = 55;
- tekstFelt.y = 178;
- tekstFelt.border = false;
- tekstFelt.width = 80;
- tekstFelt.height = 20;
- addChild(tekstFelt);
- equals = new Button();
- equals.x = 80;
- equals.y = 266;
- equals.width = 20;
- equals.label = "=";
- addChild(equals);
- equals.addEventListener(MouseEvent.CLICK, equalsClick);
- resetButton = new Button();
- resetButton.x = 100;
- resetButton.y = 266;
- resetButton.width = 40;
- resetButton.label = "CE";
- addChild(resetButton);
- resetButton.addEventListener(MouseEvent.CLICK, resetButtonClick);
- button1 = new Button();
- button1.x = 50;
- button1.y = 200;
- button1.width = 30;
- button1.label = "1";
- addChild(button1);
- button1.addEventListener(MouseEvent.CLICK, button1Click);
- button2 = new Button();
- button2.x = 80;
- button2.y = 200;
- button2.width = 30;
- button2.label = "2";
- addChild(button2);
- button2.addEventListener(MouseEvent.CLICK, button2Click);
- button3 = new Button();
- button3.x = 110;
- button3.y = 200;
- button3.width = 30;
- button3.label = "3";
- addChild(button3);
- button3.addEventListener(MouseEvent.CLICK, button3Click);
- button4 = new Button();
- button4.x = 50;
- button4.y = 222;
- button4.width = 30;
- button4.label = "4";
- addChild(button4);
- button4.addEventListener(MouseEvent.CLICK, button4Click);
- button5 = new Button();
- button5.x = 80;
- button5.y = 222;
- button5.width = 30;
- button5.label = "5";
- addChild(button5);
- button5.addEventListener(MouseEvent.CLICK, button5Click);
- button6 = new Button();
- button6.x = 110;
- button6.y = 222;
- button6.width = 30;
- button6.label = "6";
- addChild(button6);
- button6.addEventListener(MouseEvent.CLICK, button6Click);
- button7 = new Button();
- button7.x = 50;
- button7.y = 244;
- button7.width = 30;
- button7.label = "7";
- addChild(button7);
- button7.addEventListener(MouseEvent.CLICK, button7Click);
- button8 = new Button();
- button8.x = 80;
- button8.y = 244;
- button8.width = 30;
- button8.label = "8";
- addChild(button8);
- button8.addEventListener(MouseEvent.CLICK, button8Click);
- button9 = new Button();
- button9.x = 110;
- button9.y = 244;
- button9.width = 30;
- button9.label = "9";
- addChild(button9);
- button9.addEventListener(MouseEvent.CLICK, button9Click);
- }
- public function adder(tall1:int, tall2:int) : int
- {
- tekstFelt.text =(tall2 + "+" + tall1);
- return tall1+tall2;
- }
- public function equalsClick(e:MouseEvent) : void
- {
- sum = adder(tall1, tall2);
- tekstFelt.text = String(sum);
- }
- public function button1Click(event:MouseEvent) : void
- {
- if (tall1 <= 0)
- {
- tall1 = 1;
- tekstFelt.text = (1+"")
- }
- else if (tall1 >= 0)
- {
- tall2 = 1;
- tekstFelt.text = (tall1 + " + " + tall2);
- }
- }
- public function button2Click(event:MouseEvent)
- {
- if (tall1 <= 0)
- {
- tall1 = 2;
- tekstFelt.text = (""+2)
- }
- else if (tall1 >= 0)
- {
- tall2 = 2;
- tekstFelt.text = (tall1 + " + " + tall2);
- }
- }
- public function button3Click(event:MouseEvent)
- {
- if (tall1 <= 0)
- {
- tall1 = 3;
- tekstFelt.text = (3+"")
- }
- else if (tall1 >= 0)
- {
- tall2 = 3;
- tekstFelt.text = (tall1 + " + " + tall2);
- }
- }
- public function button4Click(event:MouseEvent)
- {
- if (tall1 <= 0)
- {
- tall1 = 4;
- tekstFelt.text = (4 + "")
- }
- else if (tall1 >= 0)
- {
- tall2 = 4;
- tekstFelt.text = (tall1 + " + " + tall2);
- }
- }
- public function button5Click(event:MouseEvent)
- {
- if (tall1 <= 0)
- {
- tall1 = 5;
- tekstFelt.text = (5 +"")
- }
- else if (tall1 >= 0)
- {
- tall2 = 5;
- tekstFelt.text = (tall1 + " + " + tall2);
- }
- }
- public function button6Click(event:MouseEvent)
- {
- if (tall1 <= 0)
- {
- tall1 = 6;
- tekstFelt.text = (6 + "")
- }
- else if (tall1 >= 0)
- {
- tall2 = 6;
- tekstFelt.text = (tall1 + " + " + tall2);
- }
- }
- public function button7Click(event:MouseEvent)
- {
- if (tall1 <= 0)
- {
- tall1 = 7;
- tekstFelt.text = (7 + "")
- }
- else if (tall1 >= 0)
- {
- tall2 = 7;
- tekstFelt.text = (tall1 + " + " + tall2);
- }
- }
- public function button8Click(event:MouseEvent)
- {
- if (tall1 <= 0)
- {
- tall1 = 8;
- tekstFelt.text = (8 + "")
- }
- else if (tall1 >= 0)
- {
- tall2 = 8;
- tekstFelt.text = (tall1 + " + " + tall2);
- }
- }
- public function button9Click(event:MouseEvent)
- {
- if (tall1 <= 0)
- {
- tall1 = 9;
- tekstFelt.text = (9 + "")
- }
- else if (tall1 >= 0)
- {
- tall2 = 9;
- tekstFelt.text = (tall1 + " + " + tall2);
- }
- }
- public function resetButtonClick(event:MouseEvent)
- {
- tall1 = 0;
- tall2 = 0;
- tekstFelt.text = ("" + 0);
- }
- }
- }
Add Comment
Please, Sign In to add comment