Controlling Audio / Scripting the Jukebox pt. 2
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
Continuing from the previous movie my review of the scripts for getting your Jukebox project scripted correctly and working, we now come to the portion of the script where we're going to set up the volume control. Let's go ahead and move my Actions Window over there and open this up so we can see all of my remarks. First we're going to run a function for the mute button. Do the mute button first because that's a good way to test that your script is working, by pressing the mute button and all music playback should be muted. Then you can go ahead and script the other three buttons: low volume, medium volume and high volume. So first function to run when Mute underscore Btn is pressed. Type that out, enter two forward slashes at the beginning of the line to remark that line out and then function volume Mute, Mute is capitalized with an M there event colon mouse event close parentheses colon void. Don't forget the open curly brace there as we do for all of our functions. Then we're going to do this method here, this soundmixer.soundtransform property. We're going to set that and we're going to create a new sound transform object and the parameter there, zero represents volume so zero is muted. Go ahead and close the curly brace. Then what you'll want to do is go down here and don't forget to add the event listener. Let's bring these blocks of code for our event listeners for each of our four buttons. Just do the mute button first, Mute underscore Btn. Remember, that's the name of the instance, my button instance, my mute button instance that I dragged on the stage and then labeled the very first thing in this sequence here in reviewing the scripts for the Jukebox. Then add event listener mouse event click and I'm going to run the volume mute function, which is the one that I just showed you. So do those two first and then test our movie. Make sure that the music is playing back when you click on one of the song buttons and then the music should be playing and then click on the mute button and the music should be stopping. If it's not stopping, there's something wrong so you want to go back and check with my version right here, mute button. If it is working, go on to the low volume button, add a remark here, function Volume Low with a capital L for the low, event, mouse event, same as above. SoundMixer.soundtransform equals new sound transform. This time I'm going to set the new sound transform object, the property of the volume property to .15. One is full volume; zero is mute so this is going to be a very low value. Go back and add the event listener for the low volume button. Go ahead and check the low volume button to make sure that it's all working. And you can go ahead and do the next two, Copy and Paste to create the medium volume and high volume event listeners. Add the functions. Probably you want to Copy and Paste those. Change the remark and then the only thing you're really changing is this parameter for the new sound transform object; .5 for medium and then .9 for high. You can also change that to 1. Actually you can change these values to any number. These are good numbers to check to see if everything is working. And the last thing we need to do, which should be second nature to you now is test all of our scripts. First thing you want to do however is check your scripting. You might want to pause your movie to make sure that your event listeners are set up like I have them here, that your functions for you mute, low, medium and high volume buttons are properly scripted. Next, we had the functions to run when the various song buttons were pressed. Might want to pause the movie again and make sure that those are all correct. Let's go ahead and open this up again, make this job a little bit easier for you. Let's go ahead and there are the scripts for the various song buttons, Song 2 through Song 4 and then also top of the script here is the scripts for creating the various sound objects, the URL request objects and then placing the URL request data into the sound object. So once you checked your scripts, made sure that everything looks good, final test is to do Control Test Movie. You should see no errors, no problems in the output panel or the compiler error panel. Click on one of the songs, music should start playing right away. Click on the mute button; it should mute it. Low should be very low, medium should be louder, high should be louder still. Try each of the songs. Make sure they're all playing. Everything looks pretty good here. So there you have all the script required for setting up a nice little jukebox with four songs and then a volume control over here consisting of four buttons. As I mentioned previously, a good exercise for you now would be to mix the volume slider scripts with this script to replace my volume buttons with a more elegant volume slider and create a graphic perhaps that matches this Jukebox graphic up here at the top or the bottom; somewhere, perhaps down here would be a great place for a little volume slider. Takes up a lot less space than my bulky volume buttons over here. But first do the volume buttons. The idea is to start with simple scripts and then build complexity as you're successful with simpler scripts first.
Tutorial Information
| Course: | Adobe Flash ActionScript 3.0 for Designers |
| Author: | James Gonzalez |
| SKU: | 34060 |
| ISBN: | 1-935320-82-3 |
| Release Date: | 2009-11-09 |
| Duration: | 9.5 hrs / 101 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 