Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now we'll add a soundtrack to our dancing robot. If you're following along, I'm working in 05_Soundtrack.fla in the Chapter 06 folder in the Exercise Files folder. Before we go to our ActionScript, let's take a look in the library at a sound called soundtrack.mp3. This is the soundtrack for our dancing robot. If you right-click or Control-click the sound in the library and choose Linkage, you can check the Export for ActionScript box, so that we can use the soundtrack in the ActionScript. For the Class, I'm going to truncate the default name, so that the Class is simply soundtrack.
Then I'm going to click OK. Let's go the first keyframe in the actions layer and open up the Actions panel by pressing Option+F9 on the Mac, or F9 on the PC. Above all the other code for new variable called sound, and the datatype will be soundtrack, all lower case. This is the same value that we just set in the linkage properties for our sound. We'll set it equal to a new instance of the soundtrack Class. Now what this does is it creates a new instance of the soundtrack Class, which is the Class that we created in the linkage properties that we set for our soundtrack.mp3 file in the library.
When we set that Class, the base Class for that Class was the Sound Class. What that means is that we can work with our soundtrack Class just as if we're working with the Sound Class. Let's go to the next line of code and create a new variable called soundControl, with a capital C. And the datatype is going to be soundChannel, with a capital C. We'll set it equal to sound.play.
The soundChannel Class is the class that you use to control sound. When we set our soundControl object equal to the playing sound or our playing soundtrack. Let's test the movie and listen to the soundtrack. ::Music plays:: And there's our robot dancing to the soundtrack. Nice.
And now we've added a soundtrack to our dancing robot. Next we'll explore a few different ways to add interactivity to this application.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.