Showing posts with label Week 7. Show all posts
Showing posts with label Week 7. Show all posts

Thursday, February 24, 2011

Passing and Receiving Information

//creating a function that create random functionality that we can call over and over again

import flash.events.MouseEvent;

update_btn.addEventListener(MouseEvent.CLICK, updateEverything);
random_btn.addEventListener(MouseEvent.CLICK, updateRandomly);




function updateMessage(theMessage):void {
    //myTextBox.text = "Renee";  //for when the function used to say updateMessage():void
    myTextBox.text = theMessage;
}

function updateEverything(event:MouseEvent):void {
    updateMessage(input_txt.text);
}

//now creating the random function
function updateRandomly(event:MouseEvent):void {
    var randomNumber:Number = pickRandom(100);
    updateMessage(randomNumber);
   
}

function pickRandom(theRandomRange):Number {
    return Math.ceil(Math.random() * theRandomRange);
}

Homeworkios

Add multiple names to the login.
Log out button.
Delete contacts.

:void vs. Returning and Receiving Information

var globalVariable:String ="Good Morning";    
var theReturnValue:String;  


function myFunction():void { 
    globalVariable  = " Good Night "; 


myFunction();   
trace(globalVariable);   


//the change of the value changes inside that  function
//and the change is global, there is no need to return that value so the function is :void

function myFunctionThatReturnsSomething():String { 
    return (globalVariable + " Cat head");    
} 
trace(globalVariable); 

trace(myFunctionThatReturnsSomething());  



//the receiving function
//the value that you are passing is called an argument
function myOtherReturnThing(theVar):String { 
    return (globalVariable + "Round2" + theVar); 
}  

theReturnValue = myOtherReturnThing("You are Welcome ");  

trace(theReturnValue); 

///////

OUTPUT:     
 Good Night
 Good Night
 Good Night  Cat head
 Good Night Round2You are Welcome

Address Book - Code

THE ADDRESS BOOK
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:

import flash.events.MouseEvent;




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", "reneeroseperry@yahoo.com", "awesome@blah", "Zemail@email.com", "me@me.com"];
var theBirthdate: Array = [ "Mystery", "April 21", "November 16", "May 1", "February 20", "January 12" ];



/* var theSearchResult:Number = theFirstNames.indexOf("Joe");
trace(theLastNames[theSearchResult]);
//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 {
       //trace("poop");
       var addName:String = addName_txt.text;
       //trace(addName);
       theFirstNames.push(addName);
       //trace(theFirstNames);
      
       var addLast:String = addLast_txt.text;
       theLastNames.push(addLast);
       trace(theFirstNames);
       trace(theLastNames);
     
      var addEmail:String = addEmail_txt.text;
      theEmailAddress.push(addEmail);
      trace(theEmailAddress);
     
      var addDob:String = addDob_txt.text;
      theBirthdate.push(addDob);
   }
  
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) { 
          //trace("yay");
          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.";
      }
   }