Ever watch TV without sound? It's a whole lot differentand a whole lot less fun. Music and sound can do just as much for your projects as it does for TV. Even small touches, such as sound effects on buttons, make far more of an impression on someone than you could with no sound.Using Lingo it's possible to access a total of eight different sound channels. The first two of those channels are available directly in the Score.
|1. ||In the Score, right-click on the frame bar and select Effects Channels from the contextual menu to show the channels.With the effects channels visible, you can drag and drop sounds from the cast into either sound channel 1 or channel 2. Sound cast members that you place in these channels will play as the playhead moves over them, and will stop when the playhead leaves their span. If the sound is set to play looped, it will continue playing once started until it's told to stop with Lingo or until another sound is encountered in the same channel.|
|2. ||Lesson 5. For now though, you can take advantage of the enterFrame event to initiate the fade.|
|8. ||Change the default on exitFrame me, which is displayed, to on enterFrame me, then add the following line of Lingo to make the handler look like this:|
When the script is encountered, the sound in channel 1 will fade in over the course of 2.5 seconds. It is 2.5 seconds because the fadeIn() and fadeOut() methods use milliseconds for timing and there are 1000 milliseconds per second.Give the new script member the name sound_fade so it's easy to identify in the cast.
on enterFrame me
|9. ||Rewind and play the movie, then click the project1 button.It's better because the sound in project 1 now fades in nicely, but the intro sound still cuts off abruptly. It would be better if the intro sound would also fade out while the new sound faded in. Let's try using the fadeOut() method right before the fadeIn().|
|10. ||Modify the enterFrame handler to add the fadeOut() as shown here, then rewind and play the movie to test it.|
Did you really think that was going to work? Because the two sounds are in the same channel the intro sound still just cuts off when the new sound in the same channel is encountered. The solution is to move one of the sounds into channel 2.
on enterFrame me
|11. ||Stop the movie, then click and drag the project 1 sound down into sound channel number 2. Finally, modify the enterFrame handler as shown.[View full size image]|
Now, the sound playing in channel 1 will be faded out as the new sound in channel 2 is faded in, resulting in a smooth cross fade.
on enterFrame me
|12. ||Rewind and play the movie, then press the project 1 button to test the results.The sounds now cross fade smoothly, and the effect is much nicer than having the sound simply cut off.Before moving on to the next lesson, let's use the rollover sound (it's in the sound cast) on the project 1 button so that the sound plays when the button is rolled over with the mouse.|
|13. ||Stop the movie if it's playing, then open the project_button script, from the internal cast, so that you can edit it.You will add the line that plays the rollover sound to the mouseEnter handler.|
|14. ||Modify the mouseEnter handler of the behavior to add the sound line as shown here:|
There are two things to take note of here. First is that you're playing the sound in channel 3, which is only available through Lingo. Channel 3 is a good choice, because there might be background sound playing in channel 1 or 2. When using sound in a project, it's wise to be consistent with the channels you use, especially when most of the sound is under Lingo control.The other point to consider is that you are telling the sound to play member("rollover"). Notice you didn't include a cast reference, though you could have: member("rollover", "sound") would have worked just as well. As long as you have unique names for your cast members you can get away with not specifying the cast namealthough it's never a bad idea to do so.
on mouseEnter me
sprite(me.spriteNum).member = member("btn_p1_over", "buttons")
|15. ||Rewind and play the movie.The intro sound plays as well as the rollover sound when the button is rolled over with the mouse. And when the project 1 button is pressed the different background sounds cross-fade nicely as the curtains open. So far, the movie is looking pretty nice. In the next two lessons you will add a video to the Project 2 section, and then modify the button behavior so that it's not specific to any particular button, as it is now.Before moving on, stop the movie and save it.|