Advertisement
BOT_Yokel

ICS3U1 Unit 2 Activity 2: Question 1

Jul 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date: July 19, 2017
  2. // Purpose: To calculate the velocity of an object
  3.  
  4. // This line makes the button, btnDisplay wait for a mouse click
  5. // When the button is clicked, the displayVelocity function is called
  6. btnDisplay.addEventListener(MouseEvent.CLICK, displayVelocity);
  7.  
  8. // These lines make the textinputs wait for a mouse click
  9. // When any of these components are clicked, the clearLabels function is called
  10. txtinDistance.addEventListener(MouseEvent.CLICK, clearLabels);
  11. txtinTime.addEventListener(MouseEvent.CLICK, clearLabels);
  12.  
  13. // Declare Global Variables
  14. var distance:Number;   // distance
  15. var time:Number;       // time
  16.    
  17. // This is the displayVelocity function
  18. // e:MouseEvent is the click event experienced by the button
  19. // void indicates that the function does not return a value
  20. function displayVelocity(e:MouseEvent):void
  21. {
  22.     // declare the variables
  23.     var velocity:Number;      // velocity
  24.      
  25.     getData();
  26.     velocity = distance / time;
  27.     lblOutput.text = "The velocity is: " + velocity.toFixed(1) + " km/h.";
  28. }
  29.  
  30. // This is the getData function
  31. // It gets the distance and time from the user
  32. function getData()
  33. {
  34.     // complete the code here
  35.     distance = Number(txtinDistance.text)
  36.     time = Number(txtinTime.text)
  37. }
  38.  
  39. // This is the clearLabels function
  40. // e:MouseEvent is the click event experienced by the textInput
  41. // void indicates that the function does not return a value
  42. function clearLabels(e:MouseEvent):void
  43. {
  44.      lblOutput.text = "";
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement