Happy Taxday!

 

Quiz Monday

Don't forget. Work on branching, the sound object and array syntax

Phone Zone

(510) 885 3096 - but use email!

Basic Flash Tutoring

Wednesday's after class

Emails Thanks!

Everybody but:

Nim
Arrash

Basic Sound

 

Two Kinds

Event Sounds

Must download completely before beginning to play
Will play until told to stop

Stream sounds

Play as soon as enough data has been loaded.
Forces the timeline into synchronization

Keep'm Under Control

As layer in Timeline

 

Demo...

Drag onto timeline

Visual cues

Play

Notice the short loop when the movie loops on its own

 

Put in a looping command

Notice the sound plays through

Synch with keyframes (Watch out, mad elephant!)

Effects (volume and pan)...

Sync:

Event - plays from keyframe until the sound is finished, no matter what.

Start - plays the sound once. Won't play it again until it's done.

Most useful in buttons

Demo...

Source .fla

More Control Over Sound

 

Construction Junction, What's My Function?

You have to build the object to put the sound in first, but not just any object, a sound object.

Car metaphor. You need a special "sound truck" to carry the sound in before you can have its methods act on the sound. Like the engine - doesn't do us any good if it's not in the car.

Or like a tape deck. Got to have a tape in it before you can play it.

Let's construct a sound object

stop();

beat_sound=new Sound();

 

More on "new" -- objects

beat_sound.attachSound("beat01.wav")

GOTCHA!

Sounds symbols must have their "Linkage" set first. Why? Who knows...

Menu click on sound symbol
Choose "Linkage"
Set "Export for ActionScript" checkbox
Set Linkage Identifier to "beat"

zoo_sound.attachSound("beat");

zoo_sound.start();

Test...

Source .fla

 

Let's put it on a button

stop();

 

beat _sound=new Sound();

beat _sound.attachSound("beat ")

 

sound_btn.onRelease=function(){

beat _sound.start();

}

 

Test...

Source .fla

 

What happens if I keep hitting this thing? Out of control overlapping sounds!

Channels...8 max

More Control

One shot with a flag

stop();

 

soundFlag = false;

 

beat _sound = new Sound();

beat _sound.attachSound("beat ");

 

sound_btn.onRelease = function() {

if (soundFlag == false) {

beat _sound.start();

soundFlag = true;

trace(soundFlag);

}

};

 

Test...

Source .fla

 

The Best button

Sound event: onSoundComplete

stop();

 

soundFlag = false;

 

beat_sound = new Sound();

beat_sound.attachSound("beat");

 

beat_sound.onSoundComplete=function(){

soundFlag = false;

}

 

sound_btn.onRelease = function() {

trace("soundFlag at start of function is "+soundFlag);

if (soundFlag == false) {

beat_sound.start();

soundFlag = true;

} else {

beat_sound.stop();

soundFlag = false;

}

trace("soundFlag at end of function is "+soundFlag);

};

 

Test...

Source .fla

More Stupid Sound Tricks

Pan and volume

stop();

 

soundFlag = false;

 

beat_sound = new Sound();

beat_sound.attachSound("beat");

beat_sound.onSoundComplete=function(){

soundFlag = false;

}

 

sound_btn.onRelease = function() {

if (soundFlag == false) {

beat_sound.start(0,100);

soundFlag = true;

} else {

beat_sound.stop();

soundFlag = false;

}

};

 

_root.onMouseMove=function(){

myPanAmount=(_root._xmouse-50)*2;

if (myPanAmount > 100){myPanAmount=100};

if (myPanAmount < -100){myPanAmount=-100};

beat_sound.setPan(myPanAmount);

myVolLevel=-((_root._ymouse)-100);

if (myVolLevel > 100){myVolLevel=100};

if (myVolLevel < 0){myVolLevel=0};

beat_sound.setVolume(myVolLevel);

}

 

Source .fla

And More...

Look under Movie: Sound Methods, Properties and Events

 

Newest, and way useful properties:

.duration

.position

 

Let's use it...

Source .fla

Has sound_button and position_txt output

In movie script layer:

soundFlag = false;

 

zoo_sound = new Sound();

zoo_sound.attachSound("zoo");

zoo_sound.onSoundComplete=function(){

soundFlag = false;

}

 

sound_btn.onRelease = function() {

if (soundFlag == false) {

zoo_sound.start();

soundFlag = true;

} else {

zoo_sound.stop();

soundFlag = false;

gotoAndPlay(1);

}

};

 

trace("zoo_sound duration is: " + zoo_sound.duration);

 

In frame script layer, frame 10

myPosition = zoo_sound.position;

 

if (zoo_sound.position>=6000) {

gotoAndStop("roar");

}

 

In the next frame, same layer

gotoAndPlay("loop");

Arrays In Disarray

Just Kidding

 

A Metaphor

An array is a container object.

Like a chest of drawers. What count's is what's in the drawers, not the chest.

Building Arrays

The simple way:

 

myArrayVariable = [1,2,3,4]

 

The cowboy way (more to follow):

 

myArrayVariable = new Array();

myArrayVariable[0]=1

myArrayVariable[1]=2

myArrayVariable[2]=3

 

GOTCHA!

 

An array's "drawers" are numbered starting at 0

What's In Its Drawers?

General form:

myArrayVariable = [ argument1, argument2, argument3...]

 

Possibilities:

["intro", "section", "home"]

[12]

special case, sets the size of the array, not the values.

[x+1, x*y, math.random()]

[[1,2,3],["intro","section","home"], myArrayVariable]

Now What?

myArrayVariable = [123, "banana", 456, "apple"]

 

Retrieving values

trace(myArrayVariable[0]);

 

Retrieving properties

trace(myArrayVariable.length);

 

Gett'n fancy

var counter = 0;

while(counter < myArrayVariable.length){

trace(myArrayVariable[counter]);

counter++;

}

A Chance To Manipulate

Buah hahaha!

Adding to

myArrayVariable[12]="end";

myArrayVariable.push("after apple");

myArrayVariable.unshift("before 123");

 

Subtracting from

myArrayVariable.pop();

myArrayVariable.shift();

myArrayVariable.splice(1,2);

(from,to)

Other Tricks

Order them...

myArraryVariable = ["dog", "cat", "zebra", "aardvark", "moth"]

myArrayVariable.sort();

myArrayVariable.reverse();

 

Combine them...

myArrayVariable.join();

myArrayVariable.join("-");

myArrayVariable.toString();

Next Time For Arrays...

We'll build something useful.

Exercises

 

Sounds

Download some sounds

beats01.wav

gong.wav

zoo_WAV.wav

 

Make a movie with a button with a sound in its down state

 

Make a movie that has a sound on a layer and loops, with a button that jumps to a frame that stops the sound. Use the Sound Sync property "Stop"

 

Make a movie that plays two sounds with two sound objects with a button callback.

 

Advanced: Expand on the previous movie to keep sounds from playing more than once per click

Arrays

Create an array that has 5 "drawers"

 

Sort it.

 

What happens when you sort a mixed data type array? For Example: [3, "welcome", someVariable*2, "4"]

 

Write a while loop that will build an array of 10 numbers each of which is 2 more than the previous number, then put it in the output window with the .toString() method.

Super Advanced Array Exercise

Here's one to research on the web. Do the same as above, but create a Fibonacci sequence starting from 2.