Hi Everyone,
I am really sorry to everyone that I wasn't in class on Wednesday, but I've had a cold since the weekend and didn't feel good enough, nor did I want to infect everyone else. Nonetheless, you still have work to do this week. That means that next week I will not only check the homework that I assign here in this posting for week 4, but also the posting for week 3, so make certain that you have it all for me in our next class. See you then.
Carter-
- WEEK 4
- Classwork
- LINK class files
- Homework
- Exercise 1: In addition to your mockups and your bubble diagrams, please have a list of all the projects that you plan to include in your portfolio and how they will be categorized, as web, print, painting, or drawing, or whatever.
- Exercise 2: 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. You may solve this problem in any way you see fit; however, below are some suggestions:
- You may think of it like this: first, you have the top button, and then, second, you have the menu (which consists of the 4 additional buttons) that pops out below.
- Those 4 additional buttons should be inside of a movieclip.
- Then, the top button and the bottom menu movieclip should be put inside of another movieclip.
- Finally, use the visible property to make the bottom menu appear and disappear.
- Exercise 3: Type some actions using a string object, a for loop, and the length property.
- Create a new file.
- Name the first layer as or actions.
- Create a string object:
var className:String = new String("DMA 213, Interactive Multimedia"); - 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; - 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++){
}
- 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));
}
- 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 4: Create a for loop to access the months of the year with the length property.
- Open a new file.
- In this new file, create an array of the months of the year.
- 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.
- Inside the loop, place a trace() that traces the months of the year, one at a time.
- Extra Credit: Learning more about Objects and their properties.
- 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. - 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"; - 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. - 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"}; - 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"}; - 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; - 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;
- 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;
- 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.
- 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.
No comments:
Post a Comment