FORUMS: list search recent posts

Buttons to start and stop sounds

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
sherry conrads
Buttons to start and stop sounds
on Jan 19, 2010 at 8:00:39 am

I'm creating a flash page with 62 buttons. Each button plays a different sound file. I can simply add a sound file to the down state of each button, but then multiple sound files continue playing (overlap each other) since one sound doesn't stop when another button is clicked. How do I stop all sounds when clicking a button before the new sound starts please? Thanks, Sherry

Sherry


Return to posts index

Mike Smith
Re: Buttons to start and stop sounds
on Jan 19, 2010 at 9:04:40 am

I guess the neat way would depend a bit. If you were creating only one sound object, and attaching different files to it, then your problem would go away. But I guess you could try adding a stop all sounds command to each button, before the command to play its specific sound file.


Return to posts index

Marcus Geduld
Re: Buttons to start and stop sounds
on Jan 19, 2010 at 1:54:49 pm

SoundMixer.stopAll() should do it. You can add that to your button-click code:

function buttonClickHandler( event : MouseEvent ) : void
{
SoundMixer.stopAll();
... code to play a new sound ...
}

Author "After Effects Expressions"
Co-author "After Effects For Flash, Flash For After Effects"
Artistic Director, Folding Chair Classical Theatre, Inc
Senior Flash Developer, Zeitbyte.com


Return to posts index


sherry conrads
Re: Buttons to start and stop sounds
on Jan 21, 2010 at 9:10:49 am

Hey Marcus, Can you please help me understand what this error message is telling me?
Scene 1, Layer 1', Frame 1, Line 16 1120: Access of undefined property audaciousButton

Sherry


Return to posts index

Marcus Geduld
Re: Buttons to start and stop sounds
on Jan 21, 2010 at 2:01:02 pm

It's not possible to accurately diagnose an error message without seeing the code it refers to, but this one implies that your code is trying and failing to access something called audaciousButton.

Usually, this happens because, though you think there's an audaciousButton on the stage, there isn't. So check the stage and make sure that the button exists (in the same frame as the code) and is called audaciousButton.

Common forms of this error are...

- typos: audaciusButton, audaciousbutton, AudaciousButton, etc. will all cause errors. So click on the button, look in the instance-name field in the Properties Panel and make sure the instance name is letter-for-letter exactly the same as the code reference, remembering that Actionscript is case sensitive.

It's sometimes hard to see typos. Did you even notice this one: audaciusButton? (The "o" is missing.) Sometimes I copy the name from the Properties Panel and paste it into my code (or vice versa). That ensures that the names are in sync.

- confusing the Symbol name with instance name: did you call the button audaciousButton in the library but forget to name the instance on stage?

- temporal confusion: you can't refer to a button that doesn't exist yet -- or one that existed in the past but has stopped existing by the time the code runs.

So if your button is on frame 1 and your code is on frame 2, your code won't know about your button, because the button "died" before the code was "born." Similarly, code on frame 1 can't refer to a button that doesn't come into existence until frame 2.

- new keyframes: let's say I put a button on the stage and then tween it so that it has a keyframe in frame 1 and another in frame 5.

I then remember that the button needs an instance name. So I select it in frame 1 and name it myButton. It now has a name, BUT ONLY IN FRAME ONE! I need to also select it in frame 5 (and any other keyframes) and name it there, too.

And, of course, those names MUST agree: if it's called myButton in frame 1 and Mybutton in frame 5, I'll get errors.

The best way to avoid these problems is to give all objects instance names BEFORE tweening them. If you do this, the name will automatically be carried over to any new keyframes you add.

- nesting disagreement: lets say you have a MovieClip on the stage called container. Inside that MovieClip is a button called startButton. If you refer to startButton in your main-timeline code, you'll get an error. There's no such thing as startButton on the stage. You can only refer to it by writing container.startButton.

If none of these errors are in your code, then the problem is more complex, and I'd have to look at the fla to sort it out.

Author "After Effects Expressions"
Co-author "After Effects For Flash, Flash For After Effects"
Artistic Director, Folding Chair Classical Theatre, Inc
Senior Flash Developer, Zeitbyte.com


Return to posts index

sherry conrads
Re: Buttons to start and stop sounds
on Feb 4, 2010 at 10:33:08 pm

Marcus, Can you please repost the example with 4 buttons that stop a sound before starting the new sound on click. Sorry, I'm in Argentina on my laptop and can't get the earlier posts for some reason. Thanks, Sherry

Sherry


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]