Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date: July 19, 2017
- // Purpose: To calculate the velocity of an object
- // This line makes the button, btnDisplay wait for a mouse click
- // When the button is clicked, the displayVelocity function is called
- btnDisplay.addEventListener(MouseEvent.CLICK, displayVelocity);
- // These lines make the textinputs wait for a mouse click
- // When any of these components are clicked, the clearLabels function is called
- txtinDistance.addEventListener(MouseEvent.CLICK, clearLabels);
- txtinTime.addEventListener(MouseEvent.CLICK, clearLabels);
- // Declare Global Variables
- var distance:Number; // distance
- var time:Number; // time
- // This is the displayVelocity function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function displayVelocity(e:MouseEvent):void
- {
- // declare the variables
- var velocity:Number; // velocity
- getData();
- velocity = distance / time;
- lblOutput.text = "The velocity is: " + velocity.toFixed(1) + " km/h.";
- }
- // This is the getData function
- // It gets the distance and time from the user
- function getData()
- {
- // complete the code here
- distance = Number(txtinDistance.text)
- time = Number(txtinTime.text)
- }
- // This is the clearLabels function
- // e:MouseEvent is the click event experienced by the textInput
- // void indicates that the function does not return a value
- function clearLabels(e:MouseEvent):void
- {
- lblOutput.text = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement