Adobe Flash

Use a behavior to play an MP3 file

When you want to add interactivity to your document with ActionScript, you can often rely on behaviors to add the ActionScript for you. You'll use a sound behavior to play an MP3 file from the library.

  1. In the Library panel, right-click (Windows) or Control-click (Macintosh) ping.mp3 and select Linkage from the context menu.

  2. In the Linkage Properties dialog box, select Export for ActionScript and verify that Export in First Frame is selected.

  3. Verify that ping.mp3 appears in the Identifier text box, and click OK.

  4. On the Stage, select the playSound_btn instance.

  5. In the Behaviors panel (Window > Behaviors), click Add (+) and select Sound > Load Sound from Library.

  6. In the linkage ID text box, enter ping.mp3, and in the Name text box below, enter ping.

    Then click OK.

Test your document

Test your document to verify that the interactivity works as expected.

  1. Select Control > Test Movie.

  2. In the SWF file, click the left button to play Scene 2.
    When you finish viewing Scene 2, click Back.

  3. Click the middle button in Scene 1 to see the movie clip play.

  4. Click the right button to play the MP3 sound.

  5. Click the left button again to verify that the movie clip unloads.

Summary

Congratulations on learning how to create an interactive document. In a few minutes, you learned how to accomplish the following tasks:

  • Create a new scene.

  • Write ActionScript to navigate between scenes.

  • Write ActionScript to play an animated movie clip at runtime.

  • Use a behavior to play an MP3 file.

To learn more about ActionScript, take another lesson in the Basic ActionScript series.

by BrainBellupdated
Advertisement: