Introducing Sound


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.

Choose the sound cast, then select the intro sound by clicking on it. Make sure that its loop property is turned on within the Property inspector, as shown here.

3.

Click and drag the intro sound into sound channel 1 and then adjust the length of the span to make it end at frame 10, where the intro section ends. Next, make sure the loopproperty for the project1 sound is on, then drag it into sound channel 1 beginning at frame 15.

Make sure the sound for the Project 1 section ends at frame 44, which should be the last frame of that section.

With both sounds in place, the effects channels of the Score should look like so:

4.

Rewind and play the movie.

If your speakers are on, you should be able to hear the intro music playing (and looping) as the playhead sits at frame 10.

5.

Click the project 1 button to go to that section.

Immediately the intro sound cuts off and the new sound begins. In some situations that will be just fine, and may even be what you want. But for this project the sound should fade gracefully instead.

If you were to search on the word "fade" in Director's Help system you'll find the fadeIn and fadeOut methods for the sound object. Let's first see how the fadeIn sound might work to fade the Project 1 sound in over the intro sound.

6.

In the Cast panel, make the internal cast active by selecting its tab.

You're going to be creating a short Lingo frame script to fade the sound in, so making the internal cast active will cause the new script to be created in that cast.

7.

Double-click in the behavior channel at frame 15 to open a new script window.

Director displays the default on exitFrame handler. While exitFrame would work to initiate the fade command, Director fires this event at the end of the frame cycle. This could be too late, as the sound should begin playing at the start of the frame. For this, Director offers two other events you can use that are generated at the beginning of each frame: enterFrame and prepareFrame. The difference is that prepareFrame is generated just prior to the frame being drawn, and enterFrame just after the frame is drawn.

The exact order of events is known as the event hierarchy, which you will learn more about in 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:

 on enterFrame me  sound(1).fadeIn(2500) end 

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.

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.

 on enterFrame me  sound(1).fadeOut(2500)  sound(1).fadeIn(2500) end 

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.

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.

 on enterFrame me  sound(1).fadeOut(2500)  sound(2).fadeIn(2500) end 

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.

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:

 on mouseEnter me  sound(3).play(member("rollover"))  sprite(me.spriteNum).member = member("btn_p1_over", "buttons") end 

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.

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.



Macromedia Director MX 2004. Training from the Source
Macromedia Director MX 2004: Training from the Source
ISBN: 0321223659
EAN: 2147483647
Year: 2003
Pages: 166
Authors: Dave Mennenoh

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net