Advertisement
BOT_Yokel

ICS3U1 Unit 1 Activity 4: Question 3

Jul 11th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This line makes the button, btnCalculate wait for a mouse click
  2. // When the button is clicked, the displayDigits function is called
  3. btnCalculate.addEventListener(MouseEvent.CLICK, displayDigits);
  4.  
  5. // This line makes the textinput, txtinRadius wait for a mouse click
  6. // When the textinput is clicked, the clearLabels function is called
  7. txtinDigits.addEventListener(MouseEvent.CLICK, clearLabels);
  8.  
  9. // This is the displayDigits function
  10. // e:MouseEvent is the click event experienced by the button
  11. // void indicates that the function does not return a value
  12. function displayDigits(e:MouseEvent):void
  13. {
  14.     // declare the variables
  15.     var Initial:Number;
  16.     var Hundreds:Number;
  17.     var Tens:Number;
  18.     var Ones:Number;
  19.     var Remainder1:Number;
  20.     var Remainder2:Number;
  21.     var Sum:Number;
  22.  
  23.     // calculate the debt burden per year
  24.     Initial = Number(txtinDigits.text)
  25.     Remainder1 = Initial % 100
  26.     Hundreds = (Initial - Remainder1) / 100
  27.     Remainder2 = Remainder1 % 10
  28.     Tens = (Remainder1 - Remainder2) / 10
  29.     Ones = Remainder2 / 1
  30.     Sum = Hundreds + Tens + Ones
  31.  
  32.     // put the values into the labels
  33.     lblSum.text = Sum.toString();
  34. }
  35.  
  36. // This is the clearLabels function
  37. // e:MouseEvent is the click event experienced by the textinput
  38. // void indicates that the function does not return a value
  39. function clearLabels(e:MouseEvent):void
  40. {
  41.     txtinDigits.text = "";
  42.     lblSum.text = "";
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement