Monday, January 26th, 2009...1:54 pm
MMP 420 Blog
Welcome to MMP 420 blog. I’ll be using this blog to keep track of what we are doing in class and send out messages and resources.
In the first day of class we did a few things. First we solved a logic puzzle in groups. The basic setup for the puzzle is that you have three monsters and three explorers on one side of a river with a boat. All six of them want to get across to the other side. However there are two basic rules they must follow:
- There must be at least one and no more than two passengers in the boat. (monsters can drive the boat by themselves too).
- If at any time there are more monsters than explorers on either side of the river then they eat the explorers and it’s over.
All of the groups solved the puzzle using a number of different methods, trial-and-error, visualization and more. After that I showed a way to solve it by first looking at the five possible moves:
- 1 monster
- 2 monsters
- 1 monster + 1 explorer
- 2 explorers
- 1 explorer
If you get rid of moves that will either result in there being more monsters on one side or won’t change anything (like moving only one person on the first move or reversing the previous move), then it turns out that there really aren’t many options each time and solving it is not so hard.
Programming is similar in many ways. However it is a bit more complicated and there are more moves you can make. However as you start to program more you will find that if you know exactly what it is you want to do and you have an idea of the kinds of things you can do then it gets easier. We will talk more about this later when we also talk about ideas like decomposition.
I went through an example in class. Here are the .fla and .as files.
I wrote down list on the board of the basic elements of programming. Here they are (let me know if I forget anything):
| Programming Element
__________________ |
When to use it
__________________ |
Example
__________________________ |
| Events/Event Handlers | Respond to user action (mouse click, key press) or a computer event (file loaded, tween ended) | clip_mc.addEventListener( MouseEvent.MOUSE_DOWN, clickMouse);
function clickMouse(evt:MouseEvent){ |
| Data | This is information and it is the most basic element | "bob" |
| Data Type | Every piece of data has a type like String, Number, Int… | String |
| Variable | Used to store data. Give the data a name | var myname:String = “chris”; var myage:int = 77; |
| Operator | Used to change data and variables | Assignment Operator ( = ) is the one you use most. Changes the value of variables myname = “john”; += operator adds to existing number myage += 3; //add 3 years to my age -=, *=, /= do same thing but with – +* / Comparison Operators (==, <, >) compare two values and return true or false |
| Conditional Statement | Make a decision, only do something when the right condition is met, like if the score is greather than 100 then end the game. |
if(myscore > 100){
gotoAndStop("winGame");
}else{
gotoAndStop("loseGame");
}
//use if you want to see if a variable
//is one of several values
switch (mylevel){
case 4:
gotoAndStop("win");
break();
case 3:
gotoAndStop("four");
break();
case 2:
gotoAndStop("three");
break();
default:
gotoAndStop("two");
}
|
| Loop | Repeat code for either a specified number of times or until a variable is set to true | for(var i:int = 0; i<10; i++){ //code to repeat } |
| Function | Organize a number of lines of code as one group. This can make your code easier to read and also allow you to write less lines of code. | function moveClips(){ clip1_mc.x += 5; clip2_mc.x += 5; clip3_mc.x += 5; clip4_mc.x += 5; } |
| A parameter is a variable that you can give a value to when you call a function | // here a and b are parameters
function addNumbers(a:int, b:int):int{ var result:int = addNumbers(5, 2); //result will be 7 |
|
| Class/Object | This allows you to organize a bunch of functions and variables in one place. It also make the code easier to use more than once. In ActionScript 3 most things are Objects, MovieClip, Button, Array, TextField and much more. | You can use the built in Classes/objects like movie clips or create your own Classes/objects. We will cover this in more detail later. |
| Method | Name for function when it is in a class | |
| Property | Name for a variable that is part of a class |
Leave a Reply
You must be logged in to post a comment.