Advertisement
BOT_Yokel

ICS3U1 Unit 1 Activity 4: Circumference Calculator

Jul 11th, 2017
75
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 displayCircleProperties function is called
  3. btnCalculate.addEventListener(MouseEvent.CLICK, displayCircleProperties);
  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. txtinRadius.addEventListener(MouseEvent.CLICK, clearLabels);
  8.  
  9. // This is the displayCircleProperties 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 displayCircleProperties(e:MouseEvent):void
  13. {
  14.     // declare the constants
  15.     const PI:Number = 3.14159;
  16.  
  17.     // declare the variables
  18.     var radius:Number;
  19.     var area:Number;
  20.     var circumference:Number;
  21.  
  22.     // calculate the area and circumference of a circle
  23.     radius = Number(txtinRadius.text);
  24.     area = PI * radius * radius;
  25.     circumference = 2 * PI * radius;
  26.  
  27.     // put the values into the labels
  28.     lblArea.text = area.toFixed(2);
  29.     lblCircumference.text = circumference.toFixed(2);
  30. }
  31.  
  32. // This is the clearLabels function
  33. // e:MouseEvent is the click event experienced by the textinput
  34. // void indicates that the function does not return a value
  35. function clearLabels(e:MouseEvent):void
  36. {
  37. txtinRadius.text = "";
  38. lblArea.text = "";
  39. lblCircumference.text = "";
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement