Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This line makes the button, btnCalculate wait for a mouse click
- // When the button is clicked, the displayCoins function is called
- btnCalculate.addEventListener(MouseEvent.CLICK, displayCoins);
- // This line makes the textinput, txtinRadius wait for a mouse click
- // When the textinput is clicked, the clearLabels function is called
- txtinAmount.addEventListener(MouseEvent.CLICK, clearLabels);
- // This is the displayCoins function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function displayCoins(e:MouseEvent):void
- {
- // declare the variables
- var Initial:Number;
- var Quarters:Number;
- var Dimes:Number;
- var Nickels:Number;
- var Pennies:Number;
- var Remainder1:Number;
- var Remainder2:Number;
- var Remainder3:Number;
- // calculate the debt burden per year
- Initial = Number(txtinAmount.text)
- Remainder1 = Initial % 25
- Quarters = (Initial - Remainder1) / 25
- Remainder2 = Remainder1 % 10
- Dimes = (Remainder1 - Remainder2) / 10
- Remainder3 = Remainder2 % 5
- Nickels = (Remainder2 - Remainder3) / 5
- Pennies = Remainder3 / 1
- // put the values into the labels
- lblQuarters.text = Quarters.toFixed(0);
- lblDimes.text = Dimes.toFixed(0);
- lblNickels.text = Nickels.toFixed(0);
- lblPennies.text = Pennies.toFixed(0);
- }
- // 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
- {
- txtinAmount.text = "";
- lblQuarters.text = "";
- lblDimes.text = "";
- lblNickels.text = "";
- lblPennies.text = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement