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

Thursday, June 10, 2010

Summer 2010 week 5:
6/10/10: Wed, 12:25 - 3:25

Hi Everyone,

I continue to be impressed by you all as a class. You all are exactly the type of students, the type of class that teachers like to have in their classes: you are interested, you work hard, and you're enthusiastic. I look forward to Wednesday's class every week. I know the stuff we do in class isn't easy, but I'm happy that a good number of you are actually busy trying to figure it out each week. It doesn't matter if you're 100% successful each week, but rather that you try to figure it out.

Please keep it up. You will be glad you did, and by the amount that you have learned by the end of the term.

Carter-



  1. WEEK 5
    1. Classwork
      • LINK    class files
    2. Homework
      • Exercise 1:    Create a drop-down menu with 5 buttons, a top button and then 4 buttons that pop out below. To do this, you will need to nest your buttons inside various additional movieclips.
        1. Think of it like this: you have the top button, and then the menu (which consists of the 4 additional buttons) that pops out below.
        2. Those 4 additional buttons should be inside of a movieclip.
        3. Then, the top button and the bottom menu movieclip should be put inside of another movieclip.
        4. Finally, use the visible property to make the bottom menu appear and disappear.


      • Exercise 2:    Type some actions using a string object, a for loop, and the length property.
        1. Create a new file.
        2. Name the first layer as or actions.
        3. Create a string object:
          var className:String = new String("DMA 213, Interactive Multimedia");
        4. Create a new variable with the integer type, and then give it the value of the number of characters in the string object using the length property:
          var classLength:int = className.length;
        5. Create a for loop that loops a number of times equal to the number of characters in the string object:
          for(var i:int = 0; i < className.length; i++){

          }
        6. The charAt method determines which character is at a particular position in a string. For example, charAt would determine that the upper-case character M is located in position 2 in the string, DMA 213, Interactive Multimedia. Therefore, use the charAt method to indicate one-by-one the characters of the string object:
          for(var i:int = 0; i < className.length; i++){
              trace(className.charAt(i));
          }
        7. Now, let's have the above trace() explain things a little better using concatenation;
          for(var i:int = 0; i < className.length; i++){
              trace("character " + i + ": " + className.charAt(i));
          }
          The example above creates a string object and then loops through all the characters in that string using a for loop. It then outputs in a trace() each character of the string one at a time along with its index position in the string (1, 2, 3, 4, etc). Notice that we're using classTitle.length to stop the looping of the for loop; so, no matter how long the string is the loop will loop that number of times. Experiment with this by putting a shorter or longer string within the string object.


      • Exercise 3:    Create a for loop to access the months of the year with the length property.
        1. Open a new file.
        2. In this new file, create an array of the months of the year.
        3. Array objects work much like String objects in that they also have a length proerty. Using the length property of the array that you created for the months of a year, create a for loop that loops the same number of times as the number of months in the year.
        4. Inside the loop, place a trace() that traces the months of the year, one at a time.


      • Exercise 4:    Learning more about Objects and their properties.
        1. Create a new file and in that new file in the actions, create a new object, not a String object and not an Array object, but a strange type of object called an Object object.

          var myObject:Object = new Object();

          You will notice that it is the same syntax as creating a String object, a URL Request object, a Loader object, or an Array object.

        2. As I've mentioned in class, everything you deal with in ActionScript is an object. The base of all objects in ActionScript is what's called the Object Class, which means it is possible to make what is referred to as an Object object. This is the most basic and simple type of object that you can create.

          Object instances are actually what's known as dynamic, which means that you can assibn whatever properties you need without a worry of errors. For example, type the following:

          var myObject:Object = new Object();
          myObject.name = "simple thing";
          myObject.id = "123456";
          myObject.color = "blue";

        3. Another way of typing this would have been:
          var myObject:Object = {name:"simple thing", id:"123456", color:"blue"};
          This is a simpler way of doing the same thing.

        4. So, let us change the code and type the following instead:

          var student_01:Object = new Object();
          student_01.name = "John";
          student_01.id = "100000";
          student_01.major = "DMA";>


          Remember, you could also type it in the following way:

          var student_00:Object = {name:"John", id:100000, major:"DMA");

        5. Now create three more students in the same manner:

          var student_01:Object = {name:"Maria", id:100000, major:"DMA");
          var student_02:Object = {name:"Dwayne", id:100002, major:"DMA");
          var student_03:Object = {name:"Jennifer", id:100003, major:"DMA");

        6. Next, we are going to create another object, but this object contains the other 4 objects together, much like a class contains students:

          var students:Object = new Object();
          students[0] = student_00;
          students[1] = student_01
          students[2] = student_02;
          students[3] = student_03

        7. But wouldn't it make sense if the index number the number next to where it says students (the 0, 1, 2, & 3), were the ID numbers instead? It should be, and it's every easy to do:

          var students:Object = new Object();
          students[100000] = student_00;
          students[100001] = student_01;
          students[100002] = student_02;
          students[100003] = student_03;

        8. There's a small problem with this, or, rather, a more efficient way of doing it. Let's think for a moment: What if, at a later time, you decide to change the ID numbers, or realize that they are wrong and have to change them. The way the script is currently set up, you'd have to change the ID number in two places, in the script where you first create it, and then right above here. Wouldn't it be nice, wouldn't it be better if, after changing it in the first place where you created it, that it changed it later on as well, automatically?

          The answer to that is an obvious, yes! So, let's do a little test. Type the following new code:

          trace(students[100000].name);
          trace(students[student_00.id].name);


          You should get a trace with the same name two times. That's because although we typed two different things on those two lines, they actually produce the same thing. Why is that? Well, recall that the index number is the same as the ID number. This means that later on, if we changed the ID number to something totally different, we'd only have to change it one place, the beginning, and our trace would still trace the correct name. Therefore, let's change the last bit of code we typed to the following:

          var students:Object = new Object();
          students[student_00.id] = student_00;
          students[student_01.id] = student_01;
          students[student_02.id] = student_02;
          students[student_03.id] = student_03;

        9. The very last thing I'd like for you to do is to create a function that contains a for loop and this for loop should trace out all of the information within these objects, the students' names, their IDs, and their majors.





No comments:

Post a Comment