Advertisement
wewgu

Simple Calculator (SimCal)

Sep 25th, 2017
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.events.MouseEvent;
  2.  
  3. var a:Number;
  4. var b:Number;
  5. var hasilop:Number;
  6. var Tambah:Boolean = false;
  7. var Kurang:Boolean = false;
  8. var Bagi:Boolean = false;
  9. var Kali:Boolean = false;
  10.  
  11. samadengan.addEventListener(MouseEvent.CLICK, Hasil);
  12.  
  13. function Hasil(event:MouseEvent)
  14. {
  15.     if(Tambah)
  16.     {
  17.         a = Number(A.text);
  18.         b = Number(B.text);
  19.         hasilop = a+b;
  20.         hasil.text = hasilop.toString();
  21.     } else if(Kurang)
  22.     {
  23.         a = Number(A.text);
  24.         b = Number(B.text);
  25.         hasilop = a-b;
  26.         hasil.text = hasilop.toString();
  27.     } else if(Kali)
  28.     {
  29.         a = Number(A.text);
  30.         b = Number(B.text);
  31.         hasilop = a*b;
  32.         hasil.text = hasilop.toString();
  33.     } else if(Bagi)
  34.     {
  35.         a = Number(A.text);
  36.         b = Number(B.text);
  37.         hasilop = a/b;
  38.         hasil.text = hasilop.toString();
  39.     }
  40. }
  41.  
  42. tambah.addEventListener(MouseEvent.CLICK, tambahClick);
  43.  
  44. function tambahClick(event:MouseEvent)
  45. {
  46.     Tambah = true;
  47.     Kurang = false;
  48.     Kali = false;
  49.     Bagi = false;
  50.     operasi.text = "+";
  51. }
  52.  
  53. kurang.addEventListener(MouseEvent.CLICK, kurangClick);
  54.  
  55. function kurangClick(event:MouseEvent)
  56. {
  57.     Kurang = true;
  58.     Tambah = false;
  59.     Kali = false;
  60.     Bagi = false;
  61.     operasi.text = "-";
  62. }
  63.  
  64. kali.addEventListener(MouseEvent.CLICK, kaliClick);
  65.  
  66. function kaliClick(event:MouseEvent)
  67. {
  68.     Kali = true;
  69.     Tambah = false;
  70.     Kurang = false;
  71.     Bagi = false;
  72.     operasi.text = "*";
  73. }
  74.  
  75. bagi.addEventListener(MouseEvent.CLICK, bagiClick);
  76.  
  77. function bagiClick(event:MouseEvent)
  78. {
  79.     Bagi = true;
  80.     Tambah = false;
  81.     Kurang = false;
  82.     Kali = false;
  83.     operasi.text = "/";
  84. }
  85.  
  86. reset.addEventListener(MouseEvent.CLICK, resetAll);
  87.  
  88. function resetAll(event:MouseEvent)
  89. {
  90.     A.text = "";
  91.     B.text = "";
  92.     hasil.text = "";
  93.     operasi.text = "";
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement