Thursday, February 17, 2011

Class Notes - Creating an Address Book


Special kind of variable that can hold more than one value at a time, a list of information.

2 ways to create and array.
var mySecondArray:Array = ["123 Main St.", "Pooptown", "USA", 94566]

var myFirstArray:Array = new Array();
myFirstArray[0] = "poop";
myFirstArray[1] = "cat";
myFirstArray[2] = 35;

/* The top one is in "order", so "Pooptown" is second. In the second one that is listed out with numbers you could state [5] ="Pooptown" but  have it in any order in the code and it will be fifth.

Arrays can hold 
Objects/Variables -a reference to another object on the stage such a movie clip */

var myArary:Array = new Array();

myArray[0] = "Renee"; //string
myArray[1] = 35;    //number
myArray[2] = true;   //boolean

var mySecondArray:Array = ["Ross", 35, true]; 

Push and Pop
Getting information in and out. 

We are going to push information into the array. 
It always pushes the information onto the end because the other positions are fixed.

var theFirstNames:Array = ["Ross", "Joe", "Renee", "Donald", "Brian"];
trace(theFirstNames[2]); //retrieve the value from a specific index position  

The Pop always removes the value from the end.

var theFirstNames:Array = ["Ross", "Joe", "Renee", "Donald", "Brian"];   
trace(theFirstNames[2]); //retrieve the value from a specific index position 




List of Methods of an Array.




theFirstNames.splice(3, 1);  //index to start at, the number of items to delete

//(3, 1) the position you want to remove, the number of things you are taking away

theFirstNames.splice(0,0, "Donald");   //start index, # to delete (none), the value to add to the array

//index of - it searches the array and returnes the index number of the searched position


//If you want to find the last name of someone in the array:
//You find the index of the first name and make a variable to contain that number, then you trace that number "theSearchResult" of the LastNames.

var theFirstNames:Array = ["Ross", "Joe", "Renee", "Donald", "Brian", "Annelie"];  
var theLastNames:Array = ["Higgins", "La Ponza", "Rose-Perry", "Quitangon", "Lee", "Zambrana"]; 

var theSearchResult:Number = theFirstNames.indexOf("Joe"); 

The Address Book:
You have to make Several text boxes.
The one for first names has to be Input text.
The others are dynamic texts.
They are all classic text boxes.
Use static text to create the labels for the boxes.

Add a button from the components window. All you have to do is drag the button onto the stage and then name the instance of that button.

Also, you will have to  embed the fonts. You only have to do it once and it does it for all the textboxes.

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", "asdfa@ys", "", "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 = ""; (if you have something in the parenthesis then a name will already be in that field, you could have one of the names already in there to make testing easier, but it is not necessary for the final product
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
//that variable that you just created is currently a String, it has to be a number to correlate to the array position

//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 

Be able to add new entries.
Password protect the address book:
create a mc box that has your user name and password, it searches to see if it has that password if yes then you tween the search fields to become visible.
the search fields are there but they are only visible if the person enters in a user name and password that comes up true in the array.

Have the ability to add new contacts. The new contacts will be wiped out when you quit. Because we are not using PHP.

No comments:

Post a Comment