AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() Test the movie and try applying different volume levels in order to hear the difference. Otherwise, the volume change will not be applied. It's important to note that this line must be added after the play sound statement is assigned to the SoundChannel object. 5 (which is at half the full volume level).Ĭhannel1.soundTransform = volumeAdjust Then to apply the change in volume, the volumeAdjust SoundTransform object is assigned to the soundTransform property of channel1. 5 This line sets the volume property of the SoundTransform object to. 5 Then go to the playSound function (that's the listener function that's called whenever the play button is clicked) and add the following line (highlighted in bold): Set the volume property of the SoundTransform object to the desired level. VolUp_btn.addEventListener(MouseEvent.CLICK, volUp) volDown_btn.addEventListener(MouseEvent.CLICK, volDown) I will name the listener functions volUp (for increasing the volume) and volDown (for decreasing the volume): Next, let's go ahead and create the event handlers for the volume buttons. Var volumeAdjust:SoundTransform = new SoundTransform() These buttons will be made clickable in order to adjust the volume.īut first, let's go ahead an create the SoundTransform object. On the stage, you will see two small buttons: one pointing up ( volUp_btn) and one pointing down ( volDown_btn). We will just be adding the volume controls. }This code just loads the sound and creates the playing and stopping functionality. Stop_btn.addEventListener(MouseEvent.CLICK, stopSound) Play_btn.addEventListener(MouseEvent.CLICK, playSound) Var channel1:SoundChannel = new SoundChannel() Var songURL:URLRequest = new URLRequest("CheerfulSong.mp3") In the Actions Panel, you'll see that there's already some code: Open the exercise file and select the first frame of the Actions layer. You can use an if statement with an else clause in order to set constraints (which we will do later on). So if the volume property has a value that goes below 0, the sound volume comes back up. Negative values will actually increase the volume as well. But generally, you should only allow values between 0 - 1 (nothing greater nothing less) because values outside that range can end up distorting the sound. NOTE: The volume property can actually accept values that are greater than 1, as well as negative values. So this means that whatever sound is being played on that SoundChannel will have the volume adjustment applied to it. already a sound assigned to that channelĬhannel1.soundTransform = volumeAdjust This statement assigns the SoundTransform object named volumeAdjust, to the soundTransform property of the SoundChannel object named channel1. Assume that channel1 is a SoundChannel object and that there is Also notice that the soundTransform property starts with a lowercase s, while the SoundTransform class starts with an uppercase S. A SoundTransform object is what holds the value for the volume level adjustment, where as the soundTransform property of the SoundChannel class is used in order to apply that volume level adjustment to the sound. NOTE: Be aware of the distinction between a SoundTransform object (which would be an instance of the SoundTransform class) and the soundTransform property (which is a property of the SoundChannel class).
0 Comments
Read More
Leave a Reply. |