Wednesday, March 23, 2011

What I got

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.display.DisplayObject;




for (var i=0; i<20; i++) { // create a new loader object var reneeLoader:Loader = new Loader(); // relative path to the image var theURL:String = "giraffes/giraffe" + (i+1); //var theLargeURL:URLRequest = new URLRequest (theURL + ".jpg") var theThumbURL:URLRequest = new URLRequest(theURL + "_thumb.jpg") reneeLoader.load(theThumbURL); reneeLoader.name = "giraffes/giraffe" + (i+1); if (i<=4){ reneeLoader.x = 10 + (i * 110); reneeLoader.y = 20; trace("Row One" + i) } else if (i>4 && i<10){ var a:Number = i-5; reneeLoader.x = 10 + (a * 110); reneeLoader.y = 115; trace("Next row" + i) } else if (i>9 && i<15){
var b:Number = i-10;
reneeLoader.x = 10 + (b * 110);
reneeLoader.y = 215;
trace("Hello" + i)
} else {
var c:Number = i-15;
reneeLoader.x = 10 + (c * 110);
reneeLoader.y = 315;
trace("last ones" + i)
}

// adds the image to the stage
addChild(reneeLoader);


reneeLoader.addEventListener(MouseEvent.MOUSE_OVER, overImage);
function overImage(event:MouseEvent):void {
event.target.alpha = .8;
trace("fades")}

reneeLoader.addEventListener(MouseEvent.MOUSE_OUT, myMouseOut);
function myMouseOut(event:MouseEvent):void{
event.target.alpha = 1;
trace("please work")}

reneeLoader.addEventListener(MouseEvent.CLICK, clickyClicker);
function clickyClicker(event:MouseEvent):void{
trace("poooo")
var largeLoader:Loader = new Loader();
var giraffeRequest:URLRequest = new URLRequest((event.target.name) + ".jpg");
largeLoader.load(giraffeRequest);
largeLoader.x =30;
largeLoader.y = 20;
addChild(largeLoader);

// ****ISAIAH HELP HERE*****
var nameLoader:Loader = new Loader();
var fart2
nameLoader.load(fart2);
nameLoader.x=30;
nameLoader.y=50;
addChild(nameLoader);
//imageName_txt.text ="Bite me!"

/*largeLoader.createTextField("imageName_txt", 1, 10, 10, 150, 30);
imageName_txt.text = "Here's some text";*/


//imageName_txt.text = "jongggg";
/*var imageName:String = largeLoader.toString();
var pictName:String = imageName;
var pictName:URLRequest = new URLRequest(g + "_thumb.jpg")
//var pictURLReq:URLRequest = new URLRequest (imageName);
//largeLoader.load(pictURLReq);
trace (pictName);*/
// ****END OF HELP SECTION****

largeLoader.addEventListener(MouseEvent.CLICK, offClicker);
function offClicker(event:MouseEvent):void{
trace("off");
removeChild(largeLoader);
}
}




}

Thursday, March 10, 2011

Image Gallery

Previous and Next Buttons
http://www.kirupa.com/developer/mx2004/xml_flash_photogallery.htm

Address Book - With New Stuff

//RENEE ROSE-PERRY
//Address Book
//MM1132v



//------------LOGIN SCREEN - Enter User Name and Password

login_btn.addEventListener(MouseEvent.CLICK, onLogin);
function onLogin(event:MouseEvent):void {
    //trace("poop");
    var theLogin:String = login_txt.text;
    var thePass:String = passwordField_txt.text;
    var loginResult:Number = loginName.indexOf(theLogin);
    var passResult:Number = passwords.indexOf(thePass);
   
   if(loginName.indexOf(theLogin) > -1 && loginResult == passResult)
    {coverScreen.visible = false;
     login_txt.text = "";
     passwordField_txt.text = "";
     messageBox.text="";}
    else { messageBox.text = "Unacceptable entry, you dumb looser."}
}



/*entry_box.pSubmit_btn.addEventListener(MouseEvent.CLICK, submitIt);
    function submitIt(event:MouseEvent):void {
        var login:String = entry_box.pName_txt.text;
        var pass:String = entry_box.pWord_txt.text;
        var loginResult:Number = loginName.indexOf(login);
        var passResult:Number = myPassword.indexOf(pass);
       
        if(loginName.indexOf(login) > -1 && loginResult == passResult) {
            //trace(login + " is actually in here");
            //trace("WINNING");
            entry_box.visible = false;
            welcome_prompt.text = ("Welcome " + login)
        } else {
            //trace("it's not in there sucker");
            entry_box.error_txt.visible = true;
            entry_box.pName_txt.text = "";
            entry_box.pWord_txt.text = "";
            }
    }*/

//---------The VARAIBLES
var theLoader:Loader = new Loader();

var loginName:Array = ["Renee", "Donald", "Isaiah"];
var passwords:Array = ["booyah", "master", "1"];

var theFirstNames:Array = ["Ross", "Joe", "Renee", "Donald", "Brian", "Annelie", "Isaiah"];
var theLastNames:Array = ["Higgins", "La Ponza", "Rose-Perry", "Quitangon", "Lee", "Zambrana", "Bowling"];
var theEmailAddress: Array = ["ai@aiiemail", "Joe@email", "reneeroseperry@yahoo.com", "awesome@blah", "brain@mail", "Zemail@email.com", "Isaiah@iloveapple"];
var theBirthdate: Array = [ "Mystery", "April 21", "November 16", "May 1", "February 20", "January 12", "December 25" ];
var theWebsite: Array = [ "http://www.rosshiggins.com", "http://www.amazon.com", "http://www.ebay.com", "http://www.google.com", "http://www.facebook.com", "http://www.twitter.com", "http://www.mm1132.blogspot.com" ];
var thePhotos:Array = ["http://archive.liveauctioneers.com/archive4/profiles-in-history/16511/0764_3_lg.jpg",
                           "http://www.scientificillustrator.com/art/photography/wildlife-photos/malaysan-sun-bear-600w-scill-0019.jpg",
                           "http://www.pictures-of-cats.org/images/exotic-shorthair-header.jpg",
                           "http://comicsmedia.ign.com/comics/image/article/765/765210/interview-hellboys-mike-mignola-20070215024537271.jpg",
                           "http://daveibsen.typepad.com/.a/6a00d83451db4269e20115709c6af0970b-400wi",
                           "http://blog.costumecraze.com/wp-content/uploads/2010/01/sexy-teenage-mutant-ninja-turtles-costume-3.jpg",
                           "http://daveibsen.typepad.com/.a/6a00d83451db4269e20115709c6af0970b-400wi"];


//----------SEARCH for Information by NAME
search_btn.addEventListener(MouseEvent.CLICK, onClickSearch);
function onClickSearch(event:MouseEvent):void {
 var theSearchText:String = first_txt.text;
 var theSearchResult:Number = theFirstNames.indexOf(theSearchText)

 var theLastName:String =   theLastNames[theSearchResult]
 var theEmail:String = theEmailAddress[theSearchResult]
 var theDob:String = theBirthdate[theSearchResult]
 var theSite:String = theWebsite[theSearchResult]
 var thePicture:String = thePhotos[theSearchResult]
              

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


                var imageRequest:URLRequest = new URLRequest(thePicture);
                theLoader.load(imageRequest)
                    //Image Properties
                    theLoader.x = 75;
                    theLoader.y = 290;
                    theLoader.scaleX = theLoader.scaleY = 0.3
                //Loading image into the stage   
                addChild(theLoader)
   
 
 
 
  //---------WEBSITE and EMAIL Hypertext
        site_txt.addEventListener(MouseEvent.CLICK, gotoWebsite);
        email_txt.addEventListener(MouseEvent.CLICK, sendEmail);

        function gotoWebsite(event:MouseEvent):void {
            var theWebsite:String = theWebsite[theSearchResult]
            var webRequest:URLRequest = new URLRequest("http://" + theWebsite);
            navigateToURL(webRequest, "_self"); //puts it in the browser window that is already open, blank - opens it in a new window
        }
        // email
        function sendEmail(event:MouseEvent):void {
            var email:String = theEmailAddress[theSearchResult]
            var goEmail:URLRequest = new URLRequest("mailto:" + email);
            trace("sending email");
            navigateToURL(goEmail);
        }
  
}




// ------------ADD New Entry to Arrays
add_btn.addEventListener(MouseEvent.CLICK, onClickAdd);
function onClickAdd (event:MouseEvent):void {
   
       var addName:String = first_txt.text;
   
       theFirstNames.push(addName);

      
       var addLast:String = last_txt.text;
       theLastNames.push(addLast);
       trace(theFirstNames);
       trace(theLastNames);
      
       var addEmail:String = email_txt.text;
       theEmailAddress.push(addEmail);
       trace(theEmailAddress);
      
       var addDob:String = dob_txt.text;
       theBirthdate.push(addDob);
       trace(theBirthdate);
      
       var addSite:String = site_txt.text;
       theWebsite.push(addSite);
       trace(theWebsite);
     
   }
  
 

//--------------------- Delete Contacts
delete_btn.addEventListener(MouseEvent.CLICK, removeEntry);
    function removeEntry(event:MouseEvent):void {
        var removeName:String = first_txt.text; 
        var removeResult:Number = theFirstNames.indexOf(removeName)
        // Verification if Infomation is in array
        if(theFirstNames.indexOf(removeName) > -1) {
            theFirstNames.splice(removeResult,1);
            theLastNames.splice(removeResult,1);
            theEmailAddress.splice(removeResult,1);
            theBirthdate.splice(removeResult,1);
            theWebsite.splice(removeResult,1);
            thePhotos.splice(removeResult,1);
           
            messageBox.text = (removeName + " has been deleted from the Address Book");
        } else {
            messageBox.text = (removeName + " is not in the Address Book");
            first_txt.text = "";
            last_txt.text = "";
            email_txt.text = "";
            dob_txt.text = "";
            site_txt.text = "";
        }
       
    }


// --------------LOG OUT Button
 logout_btn.addEventListener(MouseEvent.CLICK, logoutUser);

 function logoutUser(event:MouseEvent):void{
    coverScreen.visible = true;
    first_txt.text = "";
    last_txt.text =  "";
    email_txt.text = "";
    dob_txt.text = "";
    site_txt.text = "";
    passwordField_txt.text = "";
    login_txt.text = "";
    removeChild(theLoader);
   
   
 }

Homeworks

New Project
Make a dynamic "light box" of 20 images.
When you click the thumbnail the image gets bigger and the background fades.
Have a button (x) that makes the image go away.


For the next week
Make next and previous buttons.
Add captions/titles.

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.";
      }
   }




 

Thursday, February 17, 2011

Class Notes - Creating an Address Book

ARRAY:

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 
Strings
Boolean
Number
Objects/Variables -a reference to another object on the stage such a movie clip */


example:
var myArary:Array = new Array();

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

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




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 

theFirstNames.push("Isaiah");   
trace(theFirstNames)  
 

theFirstNames.pop();   
trace(theFirstNames) 


OUTPUT:  
Renee
Ross,Joe,Renee,Donald,Brian,Isaiah
Ross,Joe,Renee,Donald,Brian


List of Methods of an Array.

--------------------------

trace(theFirstNames) 

theFirstNames.pop();  
trace(theFirstNames)  

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

//(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
trace(theFirstNames);  


trace(theFirstNames.indexOf("Joe"));  
//index of - it searches the array and returnes the index number of the searched position


OUTPUT:  
Renee
Ross,Joe,Renee,Donald,Brian,Isaiah
Ross,Joe,Renee,Donald,Brian
Ross,Joe,Renee,Brian
Donald,Ross,Joe,Renee,Brian
2




//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"); 
trace(theLastNames[theSearchResult]); 




---------
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", "reneeroseperry@yahoo.com", "awesome@blah", "Zemail@email.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 = ""; (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 
  
 
   






---------
Homework:
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.

Thursday, February 3, 2011

Class Notes

We can do some fairly simple tweens with AS, this is used for creating animations that are independent of the timeline.



//the tween object takes 6 arguments

make a symbol and name it circle_mc
In this demo the result should be that the circle moves to the right and stops.

import fl.transitions.Tween; //the tween isn't normally imported, so CS% does that for us. If you are not using CS5 you will have to type that in.

//to get all the imports you can highlight the word tween in the import and select view help, then copy and paste the code
import fl.transitions.easing.*;
//the * imports all of the arguments within the easing class



var tween1:Tween  = new Tween (circle_mc,
        //the first one is the object, what we want the tween to act upon


var tween1:Tween  = new Tween (circle_mc, "x"
        //all the properties that we pass, need to be a string

var tween1:Tween  = new Tween (circle_mc, "x", strong.easeOut
        //the next argument is the function

var tween1:Tween  = new Tween (circle_mc, "x", strong.easeOut, 50
        //the starting value (as in on the stage where the x and y will be, for this demo we put 50)
       //it doesn't matter where it is on the stage, it matters what you input here

var tween1:Tween  = new Tween (circle_mc, "x", strong.easeOut, 50, 450
        //the ending position, it is going to move to 450, so it is moving over 400 since we are starting at 50



var tween1:Tween  = new Tween (circle_mc, "x", strong.easeOut, 50, 450, 1, true);
        //that last 2 arguments are tied together.
        //next is a number - the duration of the tween
        //the next is boolean - whether or not to use seconds, if you put false you are using frames
        //1, true = 1 sec
        //2, false = 2 frames

-----------------------------
//Final code with no notes:
import fl.transitions.Tween;
import fl.transitions.easing.*;
var tween1:Tween  = new Tween (circle_mc, "x", Strong.easeOut, 50, 450, 1, true);
---------------------------------------------------------------------------------------

Other types of movements

var tween1:Tween  = new Tween (circle_mc, "x", Back.easeIn, 50, 450, 1, true);
var tween1:Tween  = new Tween (circle_mc, "y", Bounce.easeInOut, 50, 250, 1, true);
var tween1:Tween  = new Tween (circle_mc, "x", Elastic.easeOut, 50, 250, 3, true);

________________________________________________________________________
//RANDOM NUMBER
//often used for chance in games


var randomNumber:Number;
randomNumber = Math.random();  //picks a number 0 and 1
trace(randomNumber); 





var randomNumber:Number;
randomNumber = Math.random() * 35;     //by multiplying by 35 picks a number 0 and 35
trace(randomNumber); 
//it will never pick 0 or 35, it will be a fraction.


var randomNumber:Number;
randomNumber = Math.round(Math.random() * 35);
trace(randomNumber);
//.5 and up, rounds up. .49 and down rounds down. Like in elementary school.

var randomNumber:Number;
randomNumber = Math.floor(Math.random() * 35);
trace(randomNumber);
//rounds down always, never gives 35

var randomNumber:Number;
randomNumber = Math.ceil(Math.random() * 35);
trace(randomNumber);
//rounds up always, never give 0
--------------

//DICE
var randomNumber:Number;

function getRandom():Number {
    Math.ceil(Math.random() * 6);
}   





//now we have to call the function
var randomNumber:Number;

randomNumber = getRandom();
trace(randomNumber);

function getRandom():Number {
   return  Math.ceil(Math.random() * 6);
} 


//we need the function to return the value back, you have to add return. this is different from you have functions that just run, like a shape that spins. 



--------------------------------------------------

//DICE
make a dice 
make it a symbol. select the symbol from the library
in the timeline hit F6, six times. On each of those frames create each side of the dice.
   (hold the ctrl button to drag and place the dot)
(make sure that the symbol is still selected) and create a new layer
 in that layer AS put stop();





 back on the stage, you will have an instance of that symbol.
name it die01_mc


add the highlighted code to the AS on frame 1 of the stage
//it moves to the frame randomly


var randomNumber:Number;
randomNumber = getRandom();
trace(randomNumber); 

die01_mc.gotoAndStop(randomNumber);
function getRandom():Number {
    return Math.ceil(Math.random() * 6);
}  


-------------------
To have 4 dice each pulling a random number
you have to put it on the stage 4 times each with it's own instance name.

AS:


var randomNumber:Number;
var randomNumber2:Number;
var randomNumber3:Number;
var randomNumber4:Number;

randomNumber = getRandom();
randomNumber2 = getRandom();
randomNumber3 = getRandom();
randomNumber4 = getRandom();

trace(randomNumber, randomNumber2, randomNumber3, randomNumber4);


die01_mc.gotoAndStop(randomNumber);
die02_mc.gotoAndStop(randomNumber2);
die03_mc.gotoAndStop(randomNumber3);
die04_mc.gotoAndStop(randomNumber4);

function getRandom():Number {
    return Math.ceil(Math.random() * 6);
}


--------------------
//ADDING A BUTTON
make a symbol and add it to the stage, instance name it poop_btn




AS:
var randomNumber:Number;
var randomNumber2:Number;
var randomNumber3:Number;
var randomNumber4:Number; 

randomNumber = getRandom();
randomNumber2 = getRandom();
randomNumber3 = getRandom();
randomNumber4 = getRandom(); 

trace(randomNumber, randomNumber2, randomNumber3, randomNumber4);

poop_btn.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void {  //the void is because we are not returning a value
    //trace("click");
   
randomNumber = getRandom();
randomNumber2 = getRandom();
randomNumber3 = getRandom();
randomNumber4 = getRandom();
//we are putting the call of the function in the event handler
//if you put the function in there it is creating a new instance of that everytime

die01_mc.gotoAndStop(randomNumber);
die02_mc.gotoAndStop(randomNumber2);
die03_mc.gotoAndStop(randomNumber3);
die04_mc.gotoAndStop(randomNumber4);
}  

function getRandom():Number {
    return Math.ceil(Math.random() * 6);
}
            

Class Notes Stuffs

//TIME EVENT

//the first is the delay in  miliseconds. The second is the repeat count
//you have to add an event listener for the timer event.timer

var timer:Timer = new Timer (10,0); //1000 for real clock, 10 to  speed it up so we can see what is happening

timer.addEventListener (TimerEvent.TIMER, onTimer);
timer.start();

function onTimer(event:TimerEvent):void {
// trace(“timer”);
rectangle01.rotation +=6;  //360/60
rectangle02.rotation +=.1;  //360/60/60
rectangle03.rotation +=.00833333;  //
}

// ENTER FRAME EVENTS
//triggered when the timeline goes into a certain frame (in the playhead)
//unless you put in a stop frame it keep going at the specified frame rate

//rotating on the enter frame event



// variables
var speed:Number = 10;

// event listenters
stage.addEventListener(Event.ENTER_FRAME, onFrameLoop);
stop_mc.addEventListener(MouseEvent.CLICK, onStop);
go_mc.addEventListener(MouseEvent.CLICK, onGo);


// event handlers
function onFrameLoop(george:Event):void {
    //trace("frame");
    rectangle01_mc.rotation += speed;
} //essentially speed is 10 because that is what set the variable equal to

function onStop(event:MouseEvent):void {
    //trace("stop");
    //speed = 0;
    stage.removeEventListener(Event.ENTER_FRAME, onFrameLoop);
//you have to have both the event and the even handler (just copypaste and change add to remove)

function onGo(event:MouseEvent):void {
    //trace("go");
    //speed = 10;
    stage.addEventListener(Event.ENTER_FRAME, onFrameLoop);
}

//if you give negative number it rotates counter clockwise




// TEXT FIELDS

dynamic_txt.text = "Ross Higgins";

button_mc.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void {
    //var theInput:String = input_txt.text;
    //trace(theInput);
    dynamic_txt.text = input_txt.text;
}

//there are 2 different types of text engines now in Flash
//the TLF (CS5) more complex and allows you to link multiple boxes so that text can overflow into the next box
//The classic text box: The Static Text, The Dynamic text box (can give it an istance name so we can update it), Input Text (we can also give it an instance name in order to withdraw the information and use it in our code)
 //the fonts should automatically embedd, in the TLF text fields you have to embed them.

Thursday, January 20, 2011

Week Two Notes

Loops
Allows you to make code that is reusable and compact, so you don't have to write it out multiple times.

Two Types of Loops



// FOR LOOP
//it is customary to use the letter i as the variable in the for loop, if you have multiples the next would be j , k

// for variable - setting a condition - incrimentor

for (var i:int = 0; i < 3; i++ ) {
    trace("hello");
}

Output: 
hello
hello
hello
// < 3 (going to run it 3 times), ++ incriment operator, this will trace hello 3 times into the output panel
// you could do number instead of int but int is faster to write
// 0 is because you are setting the number from which it starts counting

for (var i:int = 0; i < 3; i++ ) {
    trace("hello");
}

for (var j:int = 0; j < 4; j++) {
    trace(j);
} 

Output: 
hello
hello
hello
0
1
2
3

for (var i:int = 0; i < 3; i++ ) {
    trace("hello");
}

for (var j:int = 0; j < 4; j++) {
    trace(j);
}

for (var k:int = 4; k > 0; k--) {
    trace(k);
} 

//counts backwards


Output: 
hello
hello
hello
0
1
2
3
4
3
2
1



// WHILE LOOP 
// for loops run a set number of times, while loops run while a condition is true (based on a condition)

var num:Number = 0;
while  (num < 0.5) {
   
}
// If you ran this it would go on and on because we have not set a condition for the while loop

var num:Number = 0; 
while  (num < 0.5) { 
    num = Math.random()
    trace(num)
}   

Output: 
// in this example as long as the number is greater than .5 it keeps going,


ARRAYS
//ARRAYS
//store multiple values in one single variable. An array is an object in flash, just like movieclips. So it is more than just a type it is an object.

//Arrays always start counting at 0

var myFirstArray:Array = new Array();
myFirstArray[0] = "poop";
trace(myFirstArray); 

Output: 
poop

//next we mix up the types of data we can put into the array

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

trace(myFirstArray);  

//another way to write it

var mySecondArray:Array = ["123 Main St.", "Pooptown", "USA", 94566]
trace(mySecondArray);  

//

Output: (of both)
poop,cat,35
123 Main St.,Pooptown,USA,94566
//you only get a line break for each trace command

// it is more common to get values out of an array vs in (like the above examples)

var mySecondArray:Array = ["123 Main St.", "Pooptown", "USA", 94566]
trace(mySecondArray[2]);  

//get the second position of the array
Output
USA

//PUSH 


//this is a way to add values into an existing array
//whatever you put inside the array it will add it onto the end of the array

mySecondArray.push("Earth");
trace(mySecondArary); 

//POP

mySecondArray.pop();
trace(mySecondArray);
//it pops of the last value of the array

Output (of both) 
123 Main St.,Pooptown,USA,94566,Earth
123 Main St.,Pooptown,USA,94566

//indexOf
//method or function (when a function is part of an object it is called a method)

var mySecondArray:Array = ["123 Main St.", "Pooptown", "USA", 94566] 
trace(mySecondArray); 


trace(myFirstArray.indexOf("cat"));
//indexOf will return a 1 if it finds the information
//if we search for something and it does not find it, it will return -1 forexample ("Cat")

Output
 poop,cat,35
1

 //FOR LOOP with an ARRAY

var mySecondArray:Array = ["123 Main St.", "Pooptown", "USA", 94566]

for (var m:int = 0; m<mySecondArray.length; m++) {
     trace(mySecondArray[m]);
     
     } 
//you could have m<4, but in case you don't remember how many values you can put the arrayname.length
//[m] you could put a number in there and it would trace out that position 4 times.

Output
123 Main St.
Pooptown
USA
94566

-----------------------------------------------------------------------------------
                                                         BREAK TIME
-------------------------------------------------------------------------------------

Three types of programming:
Sequential, Procedural, and Object Orient Programming.
Up to this point we have been using sequential coding.

Custom Functions

//FUNCTIONS
//you define the function, then you call it

function showMessage() {
    trace("hello")
}
//this will not output anything, because we have to call the function

function showMessage() {
    trace("hello dogface")


showMessage();
showMessage()
//it will output how ever many times you call it

Output 
hello dogface
hello dogface


//now we are going to write it in a more dynamic way, we are going to tell it (read more down below)

function showMessage(theMessage:String):void { 
    trace(theMessage); 
} 

showMessage("hello");
showMessage("Buttface");

Output
hello
Buttface


//passing a parameter from the call into a variable that will catch that parameter
//the parameter "hello" gets stored in the variable theMessage
//it only exists in that function, it is called a local variable
//with in that function we can use that variable anytime we want

//now we can also have it run and return a value back to us for later use
function celciusToFarenheit(theCelciusNumber:Number):Number {
    return (9/5)*theCelciusNumber +32;
   
}
var theFarenheitNumber:Number = celciusToFarenheit(28);
trace(theFarenheitNumber);

//creating variable theCelciusNumber that is a Number
//:Number):Number since we are passing something as opposed to passing nothing like  :String):void
//since it is returning a value to use we need to create something to store that value into
//create a new variable theFarenheitNumber to store the value




----------------------------------------------------------------------------------
-----------------------NEW FILE-----------------------------------------------
---------------------------------------------------------------------------------
//MOUSE EVENTS
make a pentagon on the stage
make it a movieclip
give it an instance name: pentagon01_mc

//in the AS we need to create an even listener
//when the event happens/is triggered then the event handler occurs

pentagon01_mc.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void {
    trace("click");
   
}

//the eventlistener sends an  event to the handler, we named it event but we could have named it whatever we wanted such as (evt:mouseEvent)

OUTPUT 
run the script
when we click on pentagon01_mc the output panel shows click



import flash.events.MouseEvent;

pentagon01_mc.addEventListener(MouseEvent.CLICK, onClick);

function onClick(event:MouseEvent):void {
pentagon01_mc.rotation += 10;

}  


OUTPUT  
when you click on the pentagon, it rotates on the registration point


//if you need to change the registration point, you go to the library, select it, cut and paste and the point will move to the middle.
//if you need to move it back the corner you can copy and paste it and use the guides to eyeball the position, or you can set the x and y values in the properties.


//when you create a new listener you have to create a new handler to handle it
//this changes the alpha down to 80 percent 


import flash.events.MouseEvent;

pentagon01_mc.addEventListener(MouseEvent.CLICK, onClick); 
pentagon01_mc.addEventListener(MouseEvent.ROLL_OVER, onRoll); 

function onClick(event:MouseEvent):void {
    pentagon01_mc.rotation += 10;
   
}

function onRoll(event:MouseEvent):void {
    pentagon01_mc.alpha = .8;
}


//next create a third event to make the transparency come back


import flash.events.MouseEvent;

pentagon01_mc.addEventListener(MouseEvent.CLICK, onClick);
pentagon01_mc.addEventListener(MouseEvent.ROLL_OVER, onRoll);
pentagon01_mc.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut); 

function onClick(event:MouseEvent):void {
    pentagon01_mc.rotation += 10;
   
} 

function onRoll(event:MouseEvent):void {
    pentagon01_mc.alpha = .8;
} 

function onMouseOut(event:MouseEvent):void {
    pentagon01_mc.alpha = 1;
}





//KEYBOARD BOARD EVENT

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPress);
function onKeyPress(event:KeyboardEvent):void {
    trace("key pressed: " + event.keyCode);

//you can have a key up or a key down, they are basically the same except you might want key up if you are making a game and you have the user hold a key and do stuff

OUTPUT (depends on what keys you pressed)
key pressed: 83
key pressed: 68
key pressed: 70
key pressed: 65
key pressed: 83


stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPress);
function onKeyPress(event:KeyboardEvent):void {
    trace("key pressed: " + event.keyCode);
    if  (event.keyCode == 40) {
        trace("down");
    }
}

Output
key pressed: 40
down

// next add else if for the other arrow keys and else for everything else

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPress);
function onKeyPress(event:KeyboardEvent):void {
    //trace("key pressed: " + event.keyCode);
    if  (event.keyCode == 40) {
        trace("down");
    } else if (event.keyCode == Keyboard.UP) {
        trace("up");
    } else if (event.keyCode == Keyboard.LEFT) {
        trace("left");
    } else if (event.keyCode == Keyboard.RIGHT) {
        trace("right");
    } else {
        trace("you suck");
    }
}

OUTPUT
up
right
left
down
you suck

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPress);
function onKeyPress(event:KeyboardEvent):void {
    //trace("key pressed: " + event.keyCode);
    if  (event.keyCode == 40) {
        //trace("down");
        pentagon01_mc.y +=20;
    } else if (event.keyCode == Keyboard.UP) {
        //trace("up");
        pentagon01_mc.y -=20;
    } else if (event.keyCode == Keyboard.LEFT) {
        //trace("left");
        pentagon01_mc.x -=20;
    } else if (event.keyCode == Keyboard.RIGHT) {
        //trace("right");
        pentagon01_mc.x +=20;
    } else {
        trace("you suck");
    }
}


OUTPUT
You can use the arrow keys to move the shape around



HOMEWORK : Read Chapter 3

Thursday, January 13, 2011

Week 1 Demo 2

Make a star with a stroke
When you convert it to a symbol you have to select both the fill and the stroke.


name all the instances: star01_mc, star02_mc, star03_mc

//PROPERTIES
// all properties use the period . syntax

//reposition
star03_mc.x = 400;   //this repositions star03_mc over 400 pixels
star03_mc.y = 322;


//it moves absolutely from the upper left hand corner, it is not based on where it started on the stage.



//transparency
star02_mc.alpha = .5;  //transparency; uses decimals as percentages

//rotation
star03_mc.rotation = 180;
//you can use a number greater than 360, it just keeps going. A negative number makes it go counter clockwise.

//scale
star03_mc.scaleX=.2; //1.2 would scale it up 120%
star03_mc.scaleY=.2;  //have to scale both x and y to be proportional

//or you can combine it like this:
star02_mc.scaleX = star02_mc.scaleY =1.2; //

//not there - invisible
star01_mc.visible = false;
// it is not there, as opposed to alpha 0 where it is still there be not visible. The object is technically still on the stage but would not be click-able if it were a button for example.




Homework : 
Read Chapters 1 and 2

Week One Notes

Reviewing Flash
We are not using the time-line.
Properties Tab - click on stuff and get info like position and stroke. All of the properties in the properties palette is also accessible via action scripting.
Library Pallete - when we create shapes they go into the library.
     ie. make a square with the tool, click on Modify (at the top), select convert to symbol

     Shapes
     Button has interactivity built into it.
     Movie clip like a graphic but has its own time, independant of the main timeline.
     Registration point  (you can set it, usually we pick the top left corner or the center)


After creating the square into the library, anytime it appears on the stage it will be an instance of that original square in the library.We have to name that instance so we can call it up in the AS.


We are going to be camelCasing to nameStuff.
For Movieclips we are going to name are instances like this:   blueSquare_mc
       Text:  someWords_txt
       Buttons:   clickyThing_btn

Scripting window : F9 for the Actions Palette
In AS3 all the script is in one place, as opposed to tied to objects like AS2

    (if you get an error message when you open of the actions palette, you probably have an object selected on the stage. You have to unselect the object or you can click on the Layer1 : Frame 1

---------------

Variables: they are like a container that holds data. They can hold lots of different types of data.
var myFirstVariable = 255;

the numbers can be decimals

Data Classing = telling it what kind of data the variable contains
   var myFirstVariable:Number = 255;
  (all classes following the naming convention that they are capitalized)
  once you class you a variable it can only hold that kind of information, so if you class it as Number it can
  only hold numbers.

Comments:
// blah blah Single Line comment
/* blah blah blah Multi Line Comment */

Commonly used Data Classes
 Number
 int
 uint
String
Array


var myFirstVariable:Number = 255; //Any number including decimals
var myInteger:int = -35; // Any whole number including positive or negative
var myUnsignedInteger:uint // any non-negative whole number 
var myString:String = "hello";  //just plain text
var myArray: Array = [2,3,4,5]; // list of more than one value in a single variable

Conditionals
A structure in AS that allows flash to evaluate a condition and take a certain path. This is what separates programming language from mark-up language.

// IF STATEMENT

var a:Number = 0;
var b:String = "Ross";
var c:Boolean = false;

if ( a == 1 )   /* you use 2 equal signs because it is an operator, used for conditions to distinguish it from a single = which is like setting the value of something */

if ( a == 1 ) {
    //code goes here  
}


//   TRACE COMMAND
trace("Ross");  // traces to the output panel
trace ("Higgins");
trace (c);

//Control > Test Movie > Test to check this command in the Output Panel

----------------------New page of Code----------------------------
var a:Number = 0;
var b:String = "Ross";
var c:Boolean = false;

if (a==1) {
    //code goes here
    trace("if statement #1 was true");
}

if ( b=="george") {
    trace("Hello George");
} else {
    trace("Hello");
}
/* when you test this code the Output should say Hello, because b = "Ross". IF b ="george" it would say Hello George. */
------------------------Added more to the above code----------------------------


var a:Number = 0;
var b:String = "Ross";
var c:Boolean = false;

if (a == 1) {
    //code goes here
    trace("if statement #1 was true");
}

if (b == "george") {
    trace("Hello George");
} else {
    trace("Hello");
}

if (a==0) {
    trace ("number one is true");
} else if (b=="Ross") {
    trace("number two is true");
} else if (c==true) {
    trace("number three is true");
} else {
    trace("none of these are true");
}

//in this, if a=true then you will see "number one is true" in the output. if a and b are true you will still only get "number one is true" because with this code once it evaluates something and finds it to be true it stops there.


-------------------------------Class Break----------------------------
// OPERATORS

== equality operator
> greater than
< less than
>= greater than or equal to
<= less than or equal to

! not operator
!= not equal to

+ addition
- subtraction
* multiplication
/ division
&& and operator
|| or operator  // this looks weird on blogger, hold shift and hit \ two times


 if (a==1 && b=="Ross") {
     trace("both are true");
 }
 if (b=="Ross" || c==false) {
     trace ("at least one of these are true");
 }

 if (!c) {  //shorthand for (c==false) because c is boolean
    trace("the variable is false");
}
if (a!=1) {
    trace("the variable does not equal 1");
}
if (b!="ross") {
    trace("the varaible does not equal the string ross");
}

------------------New Code---------------
var a:Number = 0;
var b:String = "Ross";
var c:Boolean = false;

//SWITCH

/*
switch ("George") {
    case "ross":
        trace("one");
       
    case "George":
        trace("two");
       
    case "Ross":
        trace("three");
} */

/* switch - in the case that the value = "ross" it will trace "one"
      once it finds one that is true then it continues to run all the code aftre it
      so, in this case you will get  "two" and "three"
      even though "George" is not case "Ross"
      --You have to add BREAK to stop it from running*/

switch ("George") {
    case "ross":
        trace("one");
       
    case "George":
        trace("two");
        break;
       
    case "Ross":
        trace("three");
        break;
    default:
         trace ("other");
}