1. week 1
  2. week 2
  3. week 3
  4. week 4
  5. week 5
  6. week 6
  7. week 7
  8. week 8
  9. week 9
  10. week 10
  11. week 11
  12. week 12
  13. week 13

Saturday, June 5, 2010

Summer 2010 week 4:
6/03/10: Wednesdays 12:25 - 3:25

Hi Everyone,
Sorry that I didn't post on Thursday of this week. Because of Graduation on Thursday, I was unable. Just think, all of you will be walking in graduation this time next year if you decide to attend, and I hope you do. Some of you will more than likely already be enrolled in another 4-yr school or working in a job, but I hope you will take the time to come back and be rewarded for all of your hard work here at TCI.

Carter-



  1. WEEK 4
    1. Classwork
      • LINK    class file
    2. Homework
      • Exercise 1:    Add 2 more buttons and 2 more external files to the little site that we worked on this week and make sure you make them function like the others.


      • Exercise 2:    Look in your book and read the pages that have to do with Looping Statements, such as for loops. These are special and VERY commonly used statements. You should then create a file that demonstrates the use of a for statement together with an array. Now in your array, you should place the days of the week, and your looping statement should trace the days of the week, one on each line.


      • Exercise 3:    We are going to create a few new files that demonstrate various types of functions, including some that return & pass a value.
        1. At the very bottom of everything in ActionScript coding, there are really only 2 kinds of functions: those that are supposed to return a value and those that are not. Let's look an example of a function.
        2. Type the following code into a new file:
          1. function countToTen():void {
          2.     for (var i:uint = 1; i <= 10; i++) {
          3.         trace(i);
          4.    }
          5. }
        3. Now, create a basic but fully-functioning button on your stage and make it call that function.
        4. This countToTen() function is a good example of a type of function that DOES NOT return a value. It simply performs an action. In this case, it performs a for loop, and within that function it performs a trace. It, however does not send back any value to the spot in the code where the function was called. That is probably difficult to understand, but we can call this function and let it run its course, but at the end, the function does not contain a value that may be used further by any additional code. We specified void as the return type. Void means empty, nothing, and that is the return type. This essentially means that we are returning nothing to the function. This lets Flash know that it is not to return any value.
        5. If a function IS supposed to return a value to the place in the code from where the function was called, then the function needs to include the return keyword followed by the data being returned:
                return data;

        6. What the hell do I mean by "return a value"? Well, you have seen a function called without any values returned above. When a function DOES return a value, it is as if the call to the function (often at the end of a listener), that spot in the code where we invoke the function is replaced with some value returned by the function. For example, one other way (besides in a listener) to call a function is as follows:
                var day:String = getDayOfWeek();

          In the function call above, we've first created a variable that is typed as a string. I talked about this in class today. That simply means that the variable will only contain some data, and that data can only be a string. After that, we have the term: getDayOfWeek();. This is a function name. I know that because of the open and close parentheses at the end of the name. This tells us that it is the name of a function. At some other point in the code, however, you as the coder will have to write that function, otherwise you will get an error. You will have to create a function named getDayOfWeek and make it do something, so that when the first line calls it, Flash will know what to do.

          Anyway, if when Flash runs the movie with that function and the first line that calls the function, getDayOfWeek(), which then determines that the day of the week is Tuesday and returns that value (the day) as a string, "Tuesday", then it is as if the line has changed. See below:

                var day:String = getDayOfWeek();
          becomes
                var day:String = "Tuesday"();
        7. Type the following code into a new file:
          1. // The line below is a variable that contains a string, the first name "John"
                    var firstName:String = "John";
          2. // The line below is another variable that also contains a string, the last name "Doe"
                    var lastName:String = "Doe";

          3. // The line below creates a function;
            // Notice that instead of void it reads String;
            // This is because it is going to return a string value
                    function getFullName():String {
          4. // The line below creates a 3rd variable that contains a string;
            // It concatenates the other 2 variables with a space in between
                            var fullName:String = firstName + " " + lastName; {
          5. // This line returns the data from the variable, fullName
                            return fullName;
          6.         }

          7. // The line below creates a 4rd variable that contains a string;
            // This line also calls the function getFullName;
            // and places the string value it returns into the variable
                    var userName:String = getFullName();
          8. // This line traces whatever happens to be contained by the variable
                    trace(userName);
        8. The getFullName() function has been given the return type of String. Inside the function we create a string variable and assign the combined values of the firstName and lastName variables created inside the function. This new variable, fullName, is then returned out of the function using the return keyword back to the place in the code from where the function was called.

          Because the getFullName() function has a String return type, we can assign the result of this function to a new variable, userName, that is typed as String as the other variables were. If username had been declared as a Number instead of a String, Flash would send back an error. We would then know something was wrong, that we had tried to assign a string to a variable that was intended to hold a number.


        9. Extra credit:    Instead of having the function above run automatically when you export the movie (cmd-enter), have the function run ONLY when you click on a button and have it produce exactly the same results.





No comments:

Post a Comment