Instruction: Instructor will show students how to import and play simple audio files. Instructor will also show how to create simple controls for those sounds.
Description: This lab consists of three parts. Exercise 1 involves incorporating sinple sounds into an animation. Exercise 2 involves using simple ActionScript to control sounds. Exercise 3 involves lip syncing a character.
Note: All resource files needed to complete these exercises are on the G drive.
On the buttons layer, drag an instance of the btnStart symbol onto the radio (yes, that is a radio); you don’t need to name the instance yet.
Edit the btnStart symbol in the library; add a keyframe to the “down” state in the SFX layer.
Select the newly created keyframe, drag rockin1.wav from the library onto the stage; it will appear on the timeline.
Change the sync of the sound to “Event”.
Test the movie and press the green button, the sound is 14 seconds long. As you press the button multiple times, you will notice it plays multiple instances of the sound on top of one another. Sync:Event tells Flash to play the sound every time it reaches that frame.
Edit the btnStart symbol again, changing the sync of the sound to “Start”
Test the movie again. This time, only one instance of the sound plays, no matter how many times you press the button. Sync:Start tells Flash to start the sound, if it is already playing, it ignores this command.
Edit the btnStart symbol one more time; change the sound from “repeat” to “loop”. Obviously, this tells the sound to continue looping itself. Rockin1.wav is a sound intended to loop so there will be no break in the music when it loops.
Go back to the main timeline and drag an instance of the btnStop symbol onto the radio.
Edit the btnStop symbol, adding a keyframe on the “down” state in the SFX layer.
With this keyframe selected, select “rockin1.wav” from the “sound” dropdown in the properties bar. This does the same thing as dragging sounds from the library, but can be a timesaver if you end up with a lot of sounds.
Change the Sync of the sound to “Stop”.
Test the movie. After pressing the green button, the sound will loop until you press the red button
Also included is a movieclip titled Thump with an instance already on the main timeline named “thump1”. If you click on the speaker (yes, it’s a speaker), you can see its instance name in the properties bar.
Click on the btn_start instance you created, the green button. Give it the instance name “btn_start” without quotes. Likewise, give the red button the instance name “btn_stop”.
In the main timeline, click on the first frame of the actions layer, then open the actions panel. There should be one line of code, “thump1.stop();” this tells the movieclip instance “thump1” to stop playing immediately as the movie starts. This prevents the speaker from thumping when there is no music playing.
Add the following code below the existing line of code.
// When the start button is pressed, play the thump1 movieclip
function playThump( e:MouseEvent ):void {
thump1.play();
}
// When the stop button is pressed, stop the thump1 movieclip
function stopThump( e:MouseEvent ):void {
thump1.stop();
}
(The lines with forward slashes are comments and don’t affect the code.)
Test the movie, as the music comes on, the speaker should “thump” in a cheesy manner.
Navigate to window->other panels->scene
In the scene panel, click the + button to create a new scene, and drag the new scene above the previous one
Double click on the new scene's name and when the text become editable, type "opening". Name the old scene "radio" in the same fashion.
Click on the new scene in the scene panel, this brings it up in Flash, with its own timeline.
Drag an instance of stopBtn to the stage, name it btnStart
Drag the title_graphic to the stage, position it above the buttons.
Create a new layer in this scene, and name it 'actions'
Select the first keyframe in the actions panel, and press F9 to open up the actions panel if it is not already open.
In the actions panel, type this:
//stay on this screen until the play button is pressed
stop();
//Will be used to name your radio in the next scene
var myName:String = "your_name";
//event listener for our button
this.btnStart.addEventListener( MouseEvent.CLICK, startMovie );
//when the button is clicked, go to the 'radio' scene
function startMovie( e:MouseEvent ):void {
this.gotoAndPlay( 1, "radio" );
}
Open up the scene panel again, and return to the radio scene.
Select the text tool, and create a text box beneath the radio.
With the text box selected, go to the properties panel at the bottom of flash. In the upper lefthand corner of the panel, select 'dynamic text' from the dropdown menu. Name the textfield "radioName".
Open up panel with the first keyframe of the actions layer selected and type this text:
this.radioName.text = myName + "'s radio";
Test your movie; upon pressing the play button, you should be taken to the radio you created earlier, with the text beneath it saying "Youname's radio".
Objects:
Objects are a big storage variable type in flash. While you won't be dealing with them directly until project two, we are going to do a quick walkthrough today so they are familiar when they come up in a few weeks.
Create a new flash file. Name it xxx_objects.fla, with xxx being your initials.
Add a simple button to the stage. Name it "btnTest";
On the first frame of timeline, open up the actions panel ( F9 ). Add this code.
// create a new object
var myObject = new Object();
// add some information into it
myObject.myName = "A Name ( maybe yours )";
myObject.age = 26;
myObject.myButton = this.btnTest;
// trace out the details of the object
trace( myObject.myName );
trace( myObject.age );
trace( myObject.myButton );
4. Save this file.
Final Submissions:
Save your file as LastName_Firstname_L3Ex3. Submit both exercise files in a single folder named Lastname_FirstName_L3
External Assignment: Add sound ( to be used in your final project )
Add sound to the animation you created for last week's external assingment.
Background music
There must be 2 buttons that play different sounds. These sounds should not overlap ( i.e., when button one is pressed while sound 2 is playing, sound 2 stops ).
For questions or comments concerning the course or website contact Ronald J. Glotzbach.