Groups | Blog | Home
all groups > flash actionscript > august 2005 >

flash actionscript : control of sound


davidwmcintosh
8/6/2005 7:14:55 PM
I have a block of text which is fading in, and there is an audio voice which,
"Reads" the text as it is appearing.

I have added a mute button which uses the action script :
on (release) {stopAllSounds();

I also have a stop button which uses:
on (release) {stop();
stopAllSounds();

and a play button:
on (release) {play();

In the properties, I have set the sync to streaming.

I see that if I use the stop button, everything pauses, and both sound and
motion can be restarted with the play button. But if I use the Mute button (on
(release) {stopAllSounds();) I can't restart the audio.

Is there a way to:
1: unmute/restart audio (after using the on (release) {stopAllSounds();
command)
2. Maintain the sync of the audio with the fading in text if unmute is
possible?
NSurveyor
8/6/2005 8:11:34 PM
Get rid of all your code. Give your stop button the instance name: stop_btn.
Give the play button the instance name: play_btn. And give your mute toggle
button the instace name: mute_btn. Add the following script on the frame that
holds your buttons:

allSounds = new Sound();
x = 1;
mute_btn.onRelease = function(){
allSounds.setVolume((x =(x+1)%2)*100);
}
play_btn.onRelease = function(){
play();
}
stop_btn.onRelease = function(){
stop();
}

davidwmcintosh
8/6/2005 8:43:30 PM
I must be doing something incorrectly as I am getting these errors:
**Error** Scene=Scene 1, layer=play, frame=1:Line 1: Statement must appear
within on handler
allSounds = new Sound();

**Error** Scene=Scene 1, layer=play, frame=1:Line 2: Statement must appear
within on handler
x = 1;

**Error** Scene=Scene 1, layer=play, frame=1:Line 3: Statement must appear
within on handler
mute_btn.onfiltered= function(){

**Error** Scene=Scene 1, layer=play, frame=1:Line 6: Statement must appear
within on handler
play_btn.onfiltered= function

I originally had the buttons on seperate layers, but I moved them to a single
layer in order to place your code in frame #1
NSurveyor
8/6/2005 9:32:39 PM
Add the following script on the frame: Click on Frame 1. Open the Actions
Panel. Paste in the code:

allSounds = new Sound();
x = 1;
mute_btn.onRelease = function(){
allSounds.setVolume((x =(x+1)%2)*100);
}
play_btn.onRelease = function(){
play();
}
stop_btn.onRelease = function(){
stop();
}
davidwmcintosh
8/7/2005 12:00:00 AM
NSurveyor
8/7/2005 12:00:00 AM
davidwmcintosh
8/7/2005 12:00:00 AM
I did give the buttons the instance names in the properties menu that you
listed. I have them set to Buttons, not movieclips. When I changed them to
movie clips in the properties, the buttons just flashed throught their up,
over, and down states.
NSurveyor
8/7/2005 6:40:16 PM
davidwmcintosh
8/7/2005 9:04:55 PM
NSurveyor
8/8/2005 12:00:00 AM
Make the following changes:

Click on Frame 1 of the Transition 19 Layer. Open the properties panel, and
change the Sync to stream (for the Sound).

Click on Frame 149 of the Transition 20 Layer. Open the properties panel, and
change the Sync to stream (for the Sound).

Place the following code on frame 1 of the Play button layer:

_global.allSounds = new Sound();
_global.x = 1;

Click on the play_btn, Open the Actions Panel, and paste in:

on(release){
play();
}

Click on the stop_btn, Open the Actions Panel, and paste in:

on(release){
stop();
}

Click on the mute_btn, Open the Actions Panel, and paste in:

on(release){
allSounds.setVolume((x =(x+1)%2)*100);
this.label = x ? "Mute Sound" : "Unmute Sound";
}

You can get rid of the instance names if you like...

davidwmcintosh
8/8/2005 12:00:00 AM
AWSOME!! Thanks a million. Thanks for also providing code for changing the mute
button label to unmute and back.

I just have one last question. Is there any reason why a sound file would not
finish playing when set to streaming? The first sound flie cuts off half way
through. I have a WMA version that might work better than the MP3 that I am
currently using.

Thanks again for all the help. - Dave
NSurveyor
8/8/2005 12:00:00 AM
You're welcome.

When using stream, you need to have enough frames after the keyframe with the
sound on it for it to play through the whole thing. Just Insert a Frame really
far down on your layer, until you see the blue wave on the layer disappears.
Then, delete the extra frames.

Here's a diagram:



When sound gets cut off
[b]o~~~~~~~~~~~~~~~~~~~~[][/b]
^ ^ ^
| | |
First frame Sound waves Last frame

When you add more frames

[b]o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [][/b]
^ ^
^ ^
| |
| |
First frame Sound waves Extra frames
Last frame

When you delete the extra frames:

[b]o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[][/b]
^ ^
^
| |
|
First frame Sound waves Last frame
NSurveyor
8/8/2005 12:00:00 AM
davidwmcintosh
8/8/2005 8:16:06 PM
I understand exactly what you are saying.

I did have to move the sound file to it's own layer in order not to mess with
the timing of my visual transition.

Thanks again. You were extremely helpful. - Dave
NSurveyor
8/8/2005 9:58:39 PM
AddThis Social Bookmark Button