Thursday, February 24, 2011

Address Book - Code

fyi - you can make the password field have *** instead of showing the typed letters by:
1. select that textbox
2. under properties, paragraph, behaviors - select password

The code:


var loginName:Array = ["Renee", "Donald", "Ross"];
var myPassword:Array = ["booyah", "master", "Higgins"];

var theFirstNames:Array = ["Ross", "Joe", "Renee", "Donald", "Brian", "Annelie"];
var theLastNames:Array = ["Higgins", "La Ponza", "Rose-Perry", "Quitangon", "Lee", "Zambrana"];
var theEmailAddress: Array = ["ai@aiiemail", "asdfas", "", "awesome@blah", "", ""];
var theBirthdate: Array = [ "Mystery", "April 21", "November 16", "May 1", "February 20", "January 12" ];

/* var theSearchResult:Number = theFirstNames.indexOf("Joe");
//index of - it searches the array and returnes the index number of the searched position */

//first_txt.text = "";
search_btn.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void {

   var theSearchText:String = first_txt.text;  //storing the typed text into a variable when the button is clicked

//use that first name var to find the index number

 var theSearchResult:Number = theFirstNames.indexOf(theSearchText) //state the array you want to search (theFirstNames)
//then use that index number to match it to the last name index number
// at this point if you trace(theSearchResult) it gives you the index number of the theSearchText

 var theLastName:String =   theLastNames[theSearchResult]
 var theEmail:String = theEmailAddress[theSearchResult]
 var theDob:String = theBirthdate[theSearchResult]

//display that index number (lastname)
  last_txt.text =  theLastName
  email_txt.text = theEmail
  dob_txt.text = theDob

add_btn.addEventListener (MouseEvent.CLICK, addName);
   function addName (event:MouseEvent):void {
       var addName:String = addName_txt.text;
       var addLast:String = addLast_txt.text;
      var addEmail:String = addEmail_txt.text;
      var addDob:String = addDob_txt.text;
login_btn.addEventListener (MouseEvent.CLICK, submitIT);
   function submitIT(event:MouseEvent):void {
      // search the array for the user name, get that position
      var enteredName:String = login_txt.text;
      var searchedLoginName:Number = loginName.indexOf(enteredName)
      var correctPass:String = myPassword[searchedLoginName]
      // if not found
      //else is found
      //store the index number in variable
      //use that index number to look up the password in the pwarray
      //stored to var correctPass
       if ( passwordField_txt.text ==correctPass) { 
          greyBox.visible = false;
          var welcomeName:String = login_txt.text;
          login_txt.text = "";
          passwordField_txt.text = "";
          response_txt.text = "Welcome " + welcomeName + ", I deserve an A!";
      else {
            //trace("hell no")
           greyBox.visible =true;
           login_txt.text = "";
           passwordField_txt.text = "";
           response_txt.text = "You Suck, try again.";


No comments:

Post a Comment