Thursday, November 6, 2008

Sound buttons in Flash

During the break time, I review some of the flash tutorials in class. For me, the most difficult part is how to make the sound buttons in Flash. At this point, I mean how to use them to control the music in Flash project. Content is important but sound has a great contribution to the final result. I have made a correct tutorial for creating sound buttons based on class materials and the Internet. Now I want to share it with anyone who has problem with using sound in Flash. We will go through the process with Play, Stop, and Pause buttons.

1) Play – Stop:
_ Import music or sound clip to Flash.
_ Right click on the music file in the Library and choose Linkage – Export for ActionScript. Then name it in Identifier box.


_ Create two layers: one for the sound, another for buttons.
_ In layer 1, put this Action code in frame 1:
var snd = new Sound ( );
snd.attachSound (“name of the sound clip in Identifier”);

+ Note: If you want the music to play automatically at the beginning and it does not play over one another with the Play button, you add two more lines:
_root.snd.stop ( );
_root.snd.start ( );
_ In layer 2, create Play and Stop buttons.
_ Put this code in Play button:
on (release) {
_root.snd.start ( );
}
And you just change “start” to “stop” in the ActionScript for Stop button.

2) Play – Pause:
_ In a new Flash file, create two layers like the previous session.
_ In order to make Pause function, we need to put the sound clip into a Movie clip.

+ Insert – New Symbol – name the Movie Clip.
+ Import sound clip to Library. Go to the Movie clip timeline.
+ Leave the first frame, insert keyframe on frame 2.
+ In the Properties Panel at the bottom of the screen, click Sound and select your sound clip.
+ Set Sync to Stream. We do not need to loop, so just choose 0 time for Repeat.


+ From frame 2, insert a keyframe to the ending point of the sound clip based on the length of your sound.
+ Add stop action in the first frame because we just want to play the music only when the Play button is activated, not when the file is loaded at the beginning.

_ Go back to main timeline. Drag the Movie clip to layer 1.
_ Name the instance of the Movie clip.
_ Add Play and Pause buttons to layer 2.
_ Put this ActionScript to Play button:
on (release) {
tellTarget (“name of the instance”){

play ( );

}
}

You just change “play” to “stop” for the Pause button.

Ok! We have done the tutorial. Hope you will have no difficulty with sound buttons in Flash.

3) Technical information:
_ When you choose the Sync, there are two options that we need to know: Event and Stream.

+ Stream means we try to match the length of sound clip with the timeline. When the timeline ends, the sound ends too. Sound that is set as Stream should not be looped.

+ Event means sound clip plays until it is done. In other words, the length of sound is independent of the timeline’ length.

_ If you want to know the quality of sound clip formats such as WAV and MP3 in Flash, it needs experiment. I have tried a lot and figure out that WAV has good quality in both Event and Stream option. On the contrary, MP3 works well at Event but it is worse in Stream.