• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 8. Controlling Sound > Attaching Sounds

Attaching Sounds

After your new Sound object is instantiated, you must associate a sound with it. You can load an external MP3 file into your Sound object (which is covered later in this chapter), or you can attach a sound from the library. When you have multiple imported sounds in your library, you have to convey to the Sound object which one to play and control. You identify sounds in the library by using the Linkage option, just as you did in Chapter 7 when you attached a movie clip from the library to a movie-clip instance on the Stage. In addition to identifying your sound, the Linkage option exports it with the SWF file so that it will be available when called by the Sound object. When the sound is identified with the Linkage option, you attach it to the Sound object by using the method attachSound().

To attach a sound to the Sound object:

Continuing with the file you created in the preceding task, import a sound file by choosing File > Import (Command-R for Mac, Ctrl-R for Windows).

Your selected sound file appears in the library. You may import these sound formats: AIF (Mac), WAV (Windows), and MP3 (Mac and Win). More formats may be available if QuickTime is installed on your system.

Select the sound symbol in your library.

From the Options menu, choose Linkage (Figure 8.4).

Figure 8.4. Choose the Linkage option from the library for each sound you want to attach.

The Linkage Properties dialog box appears.

In the Linkage section, check the Export for ActionScript checkbox. Leave Export in first frame checked.

In the Identifier field, enter a name to identify your sound (Figure 8.5).

Figure 8.5. This sound is called guitarsLoopID and will be included in the exported SWF file.

Click OK.

Flash exports the selected sound in the SWF file with the unique identifier so that it is available to play when called by the Sound object.

Select the first frame of the main Timeline, and open the Actions panel.

Select the new Sound() statement in the Script pane.

By selecting the new Sound() statement, you make sure that your next ActionScript statement appears below it.

Choose Objects > Movie > Sound > Methods > attachSound.

In the Object field, enter the name of your Sound object.

In the Parameters field, enter the identifier of your sound file within quotation marks (Figure 8.6).

Figure 8.6. The attachSound() method attaches a sound from the library (“guitarsLoopID”) to the Sound object (mySound).

Your sound file is attached to the Sound object.

It’s very important that you specify the sound-file identifier within quotation marks. They tell Flash that the word is the literal name of the identifier and not an expression that it must evaluate to determine the name of the identifier.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint