Advertisement
BOT_Yokel

ICS3U1 Unit 2 Activity 1: Question 3

Jul 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date Completed: July 18, 2017
  2. // Purpose: Outputting written directions when given compass directions
  3.  
  4. // This line makes the button, btnDisplay wait for a mouse click
  5. // When the button is clicked, the determineDirections function is called
  6. btnDisplay.addEventListener(MouseEvent.CLICK, determineDirections);
  7.  
  8. // This line makes the textinputs: txtinOrigin wait for a mouse click
  9. // When a textinput is clicked, the clearLabel 1 functions are called
  10. txtinDirection.addEventListener(MouseEvent.CLICK, clearLabel1);
  11.  
  12. // This is the determineDirections function
  13. // e:MouseEvent is the click event experienced by the button
  14. // void indicates that the function does not return a value
  15. function determineDirections(e:MouseEvent):void
  16. {
  17.     // Declare variables
  18.     var Origin:String;
  19.     var Initial:String;
  20.     var Secondary:String;
  21.    
  22.     // Declaring source of variables
  23.     Origin = String(txtinDirection.text);
  24.    
  25.     // If statements to determine the initial direction output
  26.     if (Origin.charAt(0) == "N" || Origin.charAt(0) == "n")
  27.     {
  28.         Initial = "North"
  29.     }
  30.    
  31.     else if (Origin.charAt(0) == "S" || Origin.charAt(0) == "s")
  32.     {
  33.         Initial = "South"
  34.     }
  35.    
  36.     else if (Origin.charAt(0) == "E" || Origin.charAt(0) == "e")
  37.     {
  38.         Secondary = "East"
  39.     }
  40.    
  41.     else if (Origin.charAt(0) == "W" || Origin.charAt(0) == "w")
  42.     {
  43.         Secondary = "West"
  44.     }
  45.    
  46.     // If statements to determine the secondary direction output
  47.     if (Origin.charAt(3) == "N" || Origin.charAt(3) == "n")
  48.     {
  49.         Initial = "North"
  50.     }
  51.    
  52.     else if (Origin.charAt(3) == "S" || Origin.charAt(3) == "s")
  53.     {
  54.         Initial = "South"
  55.     }
  56.    
  57.     else if (Origin.charAt(3) == "E" || Origin.charAt(3) == "e")
  58.     {
  59.         Secondary = "East"
  60.     }
  61.    
  62.     else if (Origin.charAt(3) == "W" || Origin.charAt(3) == "w")
  63.     {
  64.         Secondary = "West"
  65.     }
  66.    
  67.     //The label output
  68.     lblInstructions.text = "Start facing " + Initial + ". Turn " + Origin.charAt(1) + Origin.charAt(2) + " degrees towards " + Secondary + ".";
  69. }
  70.  
  71. // This is the clearLabel1 function
  72. // e:MouseEvent is the click event experienced by the textinput
  73. // void indicates that the function does not return a value
  74. function clearLabel1(e:MouseEvent):void
  75.  
  76. {
  77.     lblInstructions.text = "";
  78.     txtinDirection.text = "";
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement