Advertisement
BOT_Yokel

ICS3U1 Unit 3 Activity 1: Question 1

Jul 25th, 2017
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date: July 25., 2017
  2. // Purpose: To store, track, and display the scores for an 18 round golf game
  3.  
  4. // These lines make the TextInput wait for a mouse click
  5. // When any of these components are clicked, the clearInputfunction is called
  6. txtinScore.addEventListener(MouseEvent.CLICK, clearInput);
  7.  
  8. // This line makes the button, btnAddScore wait for a mouse click
  9. // When the button is clicked, the addScore function is called
  10. btnAddScore.addEventListener(MouseEvent.CLICK, addScore);
  11.  
  12. // This line makes the button, btnDisplayScore wait for a mouse click
  13. // When the button is clicked, the displayNames function is called
  14. btnDisplayScore.addEventListener(MouseEvent.CLICK, displayNames);
  15.  
  16. // declare the global variables
  17. var ScoreCount:Array = new Array(); // array of friends' names
  18. lblPrompt1.text = "Enter the score for hole #" + (ScoreCount.length + 1)
  19.  
  20. // This is the addName function
  21. // e:MouseEvent is the click event experienced by the button
  22. // void indicates that the function does not return a value
  23. function addScore(e:MouseEvent):void
  24. {
  25.     // declare the variables
  26.     var Score:String; // Score Count entered by User
  27.     // get the score from the user
  28.     Score = txtinScore.text;
  29.     // append the score to the end of the array
  30.     ScoreCount.push(Score);
  31.     // Update the current hole number in the prompt
  32.     if (ScoreCount.length <=17)
  33.     {
  34.         lblPrompt1.text = "Enter the score for hole #" + (ScoreCount.length + 1)
  35.     }
  36.     // Disable score adding if maximum hole count is reached
  37.     else
  38.     {
  39.         lblPrompt1.text = "All scores are entered.";
  40.         txtinScore.text = "";
  41.         btnAddScore.enabled = false;
  42.     }
  43.     // display the length of the array in the label
  44.     lblArraySize.text = "Number of Golf Scores Entered: " + ScoreCount.length;
  45. }
  46.  
  47. // This is the displayNames function
  48. // e:MouseEvent is the click event experienced by the button
  49. // void indicates that the function does not return a value
  50. function displayNames(e:MouseEvent):void
  51. {
  52.     lblTotal.text = "";
  53.     for (var x=0; x < ScoreCount.length; x++)
  54.     {
  55.         lblTotal.text += "Hole " + (x+1) + ": " + ScoreCount[x] + "\r";
  56.     }
  57. }
  58.  
  59. // This is the clearInput function
  60. // e:MouseEvent is the click event experienced by the textInput
  61. // void indicates that the function does not return a value
  62. function clearInput(e:MouseEvent):void
  63. {
  64.      txtinScore.text = "";
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement