Question

I'm working on a little Flash game and I'm having troubles playing different sounds simultaneously.

For example, when the player passes through a tower, a gong sound is played; when the player jumps, a jump sound is played. Those two actions can occur at the same time, and the two sounds should be played together (overlapping) if that is the case.

Those sounds are declared as follows:

s_jumping = new Sound();  
s_jumping.attachSound("s_jump");  
s_noise2 = new Sound();  
s_noise2.attachSound("s_gong");  

And then they are called (when needed) with a simple s_jumping.start(0,1); or s_noise2.start(0,1);.
Nowhere in my code am I ever calling a s_jumping.stop() or s_noise2.stop().

Those sounds work fine when played separately, but when played together, it won't work. The first sound stops when the second sound is fired.

I thought that using new Sound() with a different variable name would mean that those sound would exist separately. Instead it's like one sound overrides the other.

What am I doing wrong?

(Note: I'm not trying to play a huge number of sounds here. In my tests there are at most 3 sounds at the same time.)

Update: after further testing, those sounds play fine if I remove one background sound that I have. So it seems I hit a limit of some kind. What's strange is that at the moment I play at most 3 or 4 sounds simultaneously. From what I read it should be OK with at least 8 sounds!
(Note: Using Flash CS4, actionscript 2, and exporting for Flash Player 8.)

Was it helpful?

Solution

OK, it appears the problem was caused by a bad use of the stop function.

Apparently, s_jumping.stop(); will stop all sounds and not only the "s_jumping" sound.

To stop just one sound, you have to pass its identifier (as declared in the sound properties under "export for ActionScript") as a parameter:

s_jumping.stop('s_jump');

I don't really understand the logic here, but at least it's now working as intended. ^^

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top