Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date Completed: July 18, 2017
- // Purpose: Outputting written directions when given compass directions
- // This line makes the button, btnDisplay wait for a mouse click
- // When the button is clicked, the determineDirections function is called
- btnDisplay.addEventListener(MouseEvent.CLICK, determineDirections);
- // This line makes the textinputs: txtinOrigin wait for a mouse click
- // When a textinput is clicked, the clearLabel 1 functions are called
- txtinDirection.addEventListener(MouseEvent.CLICK, clearLabel1);
- // This is the determineDirections function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function determineDirections(e:MouseEvent):void
- {
- // Declare variables
- var Origin:String;
- var Initial:String;
- var Secondary:String;
- // Declaring source of variables
- Origin = String(txtinDirection.text);
- // If statements to determine the initial direction output
- if (Origin.charAt(0) == "N" || Origin.charAt(0) == "n")
- {
- Initial = "North"
- }
- else if (Origin.charAt(0) == "S" || Origin.charAt(0) == "s")
- {
- Initial = "South"
- }
- else if (Origin.charAt(0) == "E" || Origin.charAt(0) == "e")
- {
- Secondary = "East"
- }
- else if (Origin.charAt(0) == "W" || Origin.charAt(0) == "w")
- {
- Secondary = "West"
- }
- // If statements to determine the secondary direction output
- if (Origin.charAt(3) == "N" || Origin.charAt(3) == "n")
- {
- Initial = "North"
- }
- else if (Origin.charAt(3) == "S" || Origin.charAt(3) == "s")
- {
- Initial = "South"
- }
- else if (Origin.charAt(3) == "E" || Origin.charAt(3) == "e")
- {
- Secondary = "East"
- }
- else if (Origin.charAt(3) == "W" || Origin.charAt(3) == "w")
- {
- Secondary = "West"
- }
- //The label output
- lblInstructions.text = "Start facing " + Initial + ". Turn " + Origin.charAt(1) + Origin.charAt(2) + " degrees towards " + Secondary + ".";
- }
- // This is the clearLabel1 function
- // e:MouseEvent is the click event experienced by the textinput
- // void indicates that the function does not return a value
- function clearLabel1(e:MouseEvent):void
- {
- lblInstructions.text = "";
- txtinDirection.text = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement