Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date: July 25., 2017
- // Purpose: To store, track, and display the scores for an 18 round golf game
- // These lines make the TextInput wait for a mouse click
- // When any of these components are clicked, the clearInputfunction is called
- txtinScore.addEventListener(MouseEvent.CLICK, clearInput);
- // This line makes the button, btnAddScore wait for a mouse click
- // When the button is clicked, the addScore function is called
- btnAddScore.addEventListener(MouseEvent.CLICK, addScore);
- // This line makes the button, btnDisplayScore wait for a mouse click
- // When the button is clicked, the displayNames function is called
- btnDisplayScore.addEventListener(MouseEvent.CLICK, displayNames);
- // declare the global variables
- var ScoreCount:Array = new Array(); // array of friends' names
- lblPrompt1.text = "Enter the score for hole #" + (ScoreCount.length + 1)
- // This is the addName function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function addScore(e:MouseEvent):void
- {
- // declare the variables
- var Score:String; // Score Count entered by User
- // get the score from the user
- Score = txtinScore.text;
- // append the score to the end of the array
- ScoreCount.push(Score);
- // Update the current hole number in the prompt
- if (ScoreCount.length <=17)
- {
- lblPrompt1.text = "Enter the score for hole #" + (ScoreCount.length + 1)
- }
- // Disable score adding if maximum hole count is reached
- else
- {
- lblPrompt1.text = "All scores are entered.";
- txtinScore.text = "";
- btnAddScore.enabled = false;
- }
- // display the length of the array in the label
- lblArraySize.text = "Number of Golf Scores Entered: " + ScoreCount.length;
- }
- // This is the displayNames function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function displayNames(e:MouseEvent):void
- {
- lblTotal.text = "";
- for (var x=0; x < ScoreCount.length; x++)
- {
- lblTotal.text += "Hole " + (x+1) + ": " + ScoreCount[x] + "\r";
- }
- }
- // This is the clearInput function
- // e:MouseEvent is the click event experienced by the textInput
- // void indicates that the function does not return a value
- function clearInput(e:MouseEvent):void
- {
- txtinScore.text = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement