Here's a self-inflicted error you're likely to hit upon as the quarter comes crashing down upon your head. Hey, I just made this same mistake twice in the past hour. I am not Spock, clearly. Let it forever be known to us as, "The Equal Sign As Used In Programming Does NOT Equal The Equal Sign as Used in Math Error."
In other words: = ≠ =
Ah ha ha ha ha ha!
We're used to saying things like "5 = 5," or "2 + 2 = 4." Ho hum. In a math context, "=" could be translated as "is." "5 is 5," or "2 + 2 is 4." In ActionScript, however, when we want to make plain old "is" statements we use the "==" operator, as in "5 == 5."
Here's the rub. In ActionScript, "=" is an active command, not a passive statement of fact. In programming, we can translate "=" as "gets" or "is now assigned the value of". For example, in ActionScript, the simple line of code written as
dx = 5;
is a command to the computer to, "under pain of death, drop whatever you were doing before and hold on to the value 5, you little maggot."
If you don't understand the difference between the two meanings, this will destroy you when you start working with if statements.
For example, here's a perfectly innocent looking function that is buggy as the day is long:
function checkLives (){ if (lives = 0) { gameOver; } // end if }
In this trashy code, the computer will interpret "lives = 0" as a command to stop whatever the hell else it is doing and set the lives variable to 0. The effect is that the computer whilst innocently checking the "if"condition freaks out (pain of death, remember) and set the "lives" variable to 0. This makes the "if" condition true and so the gameOver function runs constantly. The game ends before it begins and you, the programmer are puzzled.
What you want to write instead is something like this:
function checkLives(){ if (lives == 0) { gameOver; } // end if }
Our translation is now in line with what we actually want: "If lives equals 0, then run the gameOver function."
Here's a cool Blogue from Graham Annable (that's his "Kodiak Mary" image above). He's a story artist, animator, and "comic fellow" who works for Laika up in Portland and recently worked on Coraline.Most importantly, he's a hockey teammate of SOU's own Jill Bruhn.Some very nice stuff; this guy's good. Check it out and get inspired.
On Wednesday, Feb 18, we'll take a look at your midterm projects. . . so . . . get to work! You can present one grand project or several smaller ones. It's up to you.
On Monday, Feb 23, you'll present pseudo code, concepts, and a work schedule for your final project.
Here are the .fla demo files we covered today: sound01.fla sound02.fla shows how to add a dynamic text box sound03.fla shows how to place a movie clip on the stage with ActionScript alarm.wav
General Sound Notes 0. Wear headphones. 1. Flash accepts .wav and .mp3 directly. 2. Pre-edit your sounds as much as possible in an audio program such as Garage Band or Audacity. Only import the parts you need. Flash is a clunky and inefficient place to edit audio. 3. Flash will recompress your audio file unless you tell it not to. The recompression can make the file sound lousy. Again, you'll have more control doing this in your editing program. 4. Keep all of your sound files together with your .fla files.
Here's how to bring sound into Flash 1. File > Import > Import To Library 2. Right click on the new sound symbol in the Library. Choose Properties. 3. Set your compression choice. Raw will stop Flash from compressing any further. This is usually what I'm after. 4. You'll see a dialogue box (pictured above). Hit the "Advanced" button at the bottom right of the dialogue box. 5. Check Export for ActionScript. Export in first frame will be checked too and an identifier name will also be added. Without this step, your ActionScript won't be able to refer to this file and nothing will work. 6. Many folk recommend 24 khz for music and even 11 khz for spoken words. Lower quality sound = lower bandwidth = faster load times. Mono is often just fine.
Here's the code for the basic audio: // ActionScript 2.0 Basic Sound handling based on Andy Harris' Beginning Flash Game Programming For Dummies. Adopted by Sir Milesicles
// Creates a movie that plays a sound. Yay.
// declare a new sound object named sndFlame using the new and Sound commands. sndFlame = new Sound();
// fill the new sound object named sndFlame with an instance of the library symbol named "flame.wav" sndFlame.attachSound("flame.wav");
// start the sndFlame sound object sndFlame.start();
We'll critique your jump pieces in class on Wednesday. A quick note: 400 pixels wide seems to be about the maximum width for embeded .swf files in the blogspot blogs. Bigger widths wreck the layout. If you're working on a bigger piece you can either: 1. Not embed the swf, but post a still with a link to the .swf file. 2. Make a mini-version using the edit multiple frames onion skin option. (Save a copy BEFORE you do this--it can go hilariously wrong.)
// headsy.fla ActionScript 2.0 by Miles Inada // demonstrates how one button can control several movie clip timelines. // the head movie clips have stops on frame 1 of their timelines. // the body movie clip is looped and has a still rest frame on frame 40.
but03.onRelease = function(){ head1Ani.gotoAndStop(1); head2Ani.gotoAndStop(1); head3Ani.gotoAndPlay(2); bodyAni.gotoAndStop(40); } //this button is placed over the figure's head to reset all movie clips to 1 clearButton.onRelease = function(){ head1Ani.gotoAndStop(1); head2Ani.gotoAndStop(1); head3Ani.gotoAndStop(1); bodyAni.gotoAndPlay(1); }
Here's the code: //Actionscript 2.0 doortestAS205.fla by Miles Inada
// Declare a boolean variable named shut, whose value (true or false) will indicate whether the door is currently shut (true) or open (false). var shut:Boolean = true;
// Define the function openShutDoor. This function will check to see if the shut condition is true or false and act accordingly. function openShutDoor() { //check to see if the door is open or shut if (shut) { //if it's shut, open it theDoor.gotoAndPlay(2); //tell the program the door is now open shut = false; }else { // if it's open, shut it theDoor.gotoAndPlay(1); //tell the program the door is now shut shut = true; } //end else } // end function openShutDoor
// When theButton is clicked, run the openShutDoor function we've defined above theButton.onRelease = openShutDoor;
// theDoor is a movie clip with a stop command on frame 1