Guest User

Untitled

a guest
Feb 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. package {
  2.  
  3.  
  4. import flash.display.Sprite;
  5. import flash.events.MouseEvent;
  6. import flash.text.TextField;
  7. import fl.controls.Button;
  8.  
  9. public class CalcMain extends Sprite {
  10.  
  11. private var sum:int;
  12. private var tall1:int = 0;
  13. private var tall2:int = 0;
  14. private var tekstFelt:TextField;
  15. private var equals:Button;
  16. private var button1:Button;
  17. private var button2:Button;
  18. private var button3:Button;
  19. private var button4:Button;
  20. private var button5:Button;
  21. private var button6:Button;
  22. private var button7:Button;
  23. private var button8:Button;
  24. private var button9:Button;
  25. private var resetButton:Button;
  26. private var kalkBack:LkalkBack;
  27. private var tekstBack:LtekstBack;
  28.  
  29. public function CalcMain()
  30. {
  31.  
  32.  
  33.  
  34. kalkBack = new LkalkBack;
  35. kalkBack.x = 75;
  36. kalkBack.y = 225;
  37. addChild(kalkBack);
  38.  
  39. tekstBack = new LtekstBack;
  40. tekstBack.x = 55;
  41. tekstBack.y = 178;
  42. tekstBack.width = 80;
  43. tekstBack.height = 20;
  44. addChild(tekstBack);
  45.  
  46. tekstFelt = new TextField();
  47. tekstFelt.x = 55;
  48. tekstFelt.y = 178;
  49. tekstFelt.border = false;
  50. tekstFelt.width = 80;
  51. tekstFelt.height = 20;
  52. addChild(tekstFelt);
  53.  
  54.  
  55. equals = new Button();
  56. equals.x = 80;
  57. equals.y = 266;
  58. equals.width = 20;
  59. equals.label = "=";
  60. addChild(equals);
  61. equals.addEventListener(MouseEvent.CLICK, equalsClick);
  62.  
  63. resetButton = new Button();
  64. resetButton.x = 100;
  65. resetButton.y = 266;
  66. resetButton.width = 40;
  67. resetButton.label = "CE";
  68. addChild(resetButton);
  69. resetButton.addEventListener(MouseEvent.CLICK, resetButtonClick);
  70.  
  71. button1 = new Button();
  72. button1.x = 50;
  73. button1.y = 200;
  74. button1.width = 30;
  75. button1.label = "1";
  76. addChild(button1);
  77. button1.addEventListener(MouseEvent.CLICK, button1Click);
  78.  
  79. button2 = new Button();
  80. button2.x = 80;
  81. button2.y = 200;
  82. button2.width = 30;
  83. button2.label = "2";
  84. addChild(button2);
  85. button2.addEventListener(MouseEvent.CLICK, button2Click);
  86.  
  87. button3 = new Button();
  88. button3.x = 110;
  89. button3.y = 200;
  90. button3.width = 30;
  91. button3.label = "3";
  92. addChild(button3);
  93. button3.addEventListener(MouseEvent.CLICK, button3Click);
  94.  
  95. button4 = new Button();
  96. button4.x = 50;
  97. button4.y = 222;
  98. button4.width = 30;
  99. button4.label = "4";
  100. addChild(button4);
  101. button4.addEventListener(MouseEvent.CLICK, button4Click);
  102.  
  103. button5 = new Button();
  104. button5.x = 80;
  105. button5.y = 222;
  106. button5.width = 30;
  107. button5.label = "5";
  108. addChild(button5);
  109. button5.addEventListener(MouseEvent.CLICK, button5Click);
  110.  
  111. button6 = new Button();
  112. button6.x = 110;
  113. button6.y = 222;
  114. button6.width = 30;
  115. button6.label = "6";
  116. addChild(button6);
  117. button6.addEventListener(MouseEvent.CLICK, button6Click);
  118.  
  119. button7 = new Button();
  120. button7.x = 50;
  121. button7.y = 244;
  122. button7.width = 30;
  123. button7.label = "7";
  124. addChild(button7);
  125. button7.addEventListener(MouseEvent.CLICK, button7Click);
  126.  
  127. button8 = new Button();
  128. button8.x = 80;
  129. button8.y = 244;
  130. button8.width = 30;
  131. button8.label = "8";
  132. addChild(button8);
  133. button8.addEventListener(MouseEvent.CLICK, button8Click);
  134.  
  135. button9 = new Button();
  136. button9.x = 110;
  137. button9.y = 244;
  138. button9.width = 30;
  139. button9.label = "9";
  140. addChild(button9);
  141. button9.addEventListener(MouseEvent.CLICK, button9Click);
  142.  
  143. }
  144.  
  145. public function adder(tall1:int, tall2:int) : int
  146. {
  147. tekstFelt.text =(tall2 + "+" + tall1);
  148. return tall1+tall2;
  149. }
  150.  
  151. public function equalsClick(e:MouseEvent) : void
  152. {
  153. sum = adder(tall1, tall2);
  154. tekstFelt.text = String(sum);
  155.  
  156. }
  157.  
  158. public function button1Click(event:MouseEvent) : void
  159. {
  160. if (tall1 <= 0)
  161. {
  162. tall1 = 1;
  163. tekstFelt.text = (1+"")
  164. }
  165.  
  166. else if (tall1 >= 0)
  167. {
  168. tall2 = 1;
  169. tekstFelt.text = (tall1 + " + " + tall2);
  170. }
  171. }
  172.  
  173.  
  174. public function button2Click(event:MouseEvent)
  175. {
  176. if (tall1 <= 0)
  177. {
  178. tall1 = 2;
  179. tekstFelt.text = (""+2)
  180. }
  181.  
  182. else if (tall1 >= 0)
  183. {
  184. tall2 = 2;
  185. tekstFelt.text = (tall1 + " + " + tall2);
  186. }
  187. }
  188. public function button3Click(event:MouseEvent)
  189. {
  190. if (tall1 <= 0)
  191. {
  192. tall1 = 3;
  193. tekstFelt.text = (3+"")
  194. }
  195.  
  196. else if (tall1 >= 0)
  197. {
  198. tall2 = 3;
  199. tekstFelt.text = (tall1 + " + " + tall2);
  200. }
  201. }
  202. public function button4Click(event:MouseEvent)
  203. {
  204. if (tall1 <= 0)
  205. {
  206. tall1 = 4;
  207. tekstFelt.text = (4 + "")
  208. }
  209.  
  210. else if (tall1 >= 0)
  211. {
  212. tall2 = 4;
  213. tekstFelt.text = (tall1 + " + " + tall2);
  214. }
  215. }
  216. public function button5Click(event:MouseEvent)
  217. {
  218. if (tall1 <= 0)
  219. {
  220. tall1 = 5;
  221. tekstFelt.text = (5 +"")
  222. }
  223.  
  224. else if (tall1 >= 0)
  225. {
  226. tall2 = 5;
  227. tekstFelt.text = (tall1 + " + " + tall2);
  228. }
  229. }
  230. public function button6Click(event:MouseEvent)
  231. {
  232. if (tall1 <= 0)
  233. {
  234. tall1 = 6;
  235. tekstFelt.text = (6 + "")
  236. }
  237.  
  238. else if (tall1 >= 0)
  239. {
  240. tall2 = 6;
  241. tekstFelt.text = (tall1 + " + " + tall2);
  242. }
  243. }
  244. public function button7Click(event:MouseEvent)
  245. {
  246. if (tall1 <= 0)
  247. {
  248. tall1 = 7;
  249. tekstFelt.text = (7 + "")
  250. }
  251.  
  252. else if (tall1 >= 0)
  253. {
  254. tall2 = 7;
  255. tekstFelt.text = (tall1 + " + " + tall2);
  256. }
  257. }
  258. public function button8Click(event:MouseEvent)
  259. {
  260. if (tall1 <= 0)
  261. {
  262. tall1 = 8;
  263. tekstFelt.text = (8 + "")
  264. }
  265.  
  266. else if (tall1 >= 0)
  267. {
  268. tall2 = 8;
  269. tekstFelt.text = (tall1 + " + " + tall2);
  270. }
  271. }
  272. public function button9Click(event:MouseEvent)
  273. {
  274. if (tall1 <= 0)
  275. {
  276. tall1 = 9;
  277. tekstFelt.text = (9 + "")
  278. }
  279.  
  280. else if (tall1 >= 0)
  281. {
  282. tall2 = 9;
  283. tekstFelt.text = (tall1 + " + " + tall2);
  284. }
  285. }
  286.  
  287.  
  288. public function resetButtonClick(event:MouseEvent)
  289. {
  290. tall1 = 0;
  291. tall2 = 0;
  292. tekstFelt.text = ("" + 0);
  293. }
  294.  
  295. }
  296. }
Add Comment
Please, Sign In to add comment