Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sounds in Sequence

Status
Not open for further replies.

ImpInTraining

Programmer
Jan 27, 2007
19
US
I have a Flash program written with linked sound files exported for actionscript. Depending on certain buttons that are pushed and in the order they are pushed, the exported sound files will be identified via an array. Then when the final execution button is pressed, it executes a function which runs through a for loop and a switch statement to incriment through all of the array values one at a time to play these sound clips in sequence. I have a problem, however... two problems really.

The first problem is that all of the sounds are executing at the same time. The order of the code is:
* Create a new sound object.
* onRelease of the various buttons fill array[counter] with indicator of which sound file to play
* counter incriments.
* for loop to incriment through variables 0 through counter value.
* switch statement looks for proper case value which is based on the array[loop] value
* sound object .attachSound the proper linked sound file
* break out of switch
* sound object .start to play the sound.
* next for incriment and continue from 4 lines up - or end for loop.

I even put a .onSoundComplete within the for loop to try to keep the code from moving on prematurely, but it didn't keep the sounds from playing all at the same time.

The second problem is that all of the array indicators are initiating the same sound file instead of varying with the different buttons that are pushed. I'm sure I have the sounds linked and called appropriately, so I'm not sure why they all sound like the same sound file. If you go in the library and listen to them, they are all different.

The function looks like this:

// outside of the function
var soundObject:Sound = new Sound();

[...] // other code not essential to this problem

playTheSound_btn.onRelease = function() {
// counter is the dimension of the array variable
for (i=0;i<counter);i++){
switch (textArray){
case firstBtn :
soundObject.attachSound("firstSound");
break;
case secondBtn :
soundObject.attachSound("secondSound");
break;
case thirdBtn :
soundObject.attachSound("thirdSound");
break;
}
soundObject.onSoundComplete = function () {
trace("soundObject playing is complete");
}
// giving .start a delay of 1 second to create
// a short pause between sounds.
soundObject.start(1)
}
}

And like I said, if you have several selected sounds to play, they all play at once, even though the onSoundComplete trace statement won't show up until after they are done playing. And all of the sounds are the same file, the first sound that I imported and linked / exported to actionscript. If anyone can help me figure out where I'm going wrong, I'd appreciate it.

So
 
Well, I got rid of the problem of only one sound being played for everything, completely unrelated to the code above.

But no matter what I do, I cannot stop all the sounds from playing at the same time. Or I should say, when I try to use .onComplete to control when the sounds are played using a for() loop, it only plays the first sound, then the for() loop increments too quickly, finishing the whole count before the first sound is done playing, at least, that's what I suspect is happening.

If anyone can tell me why this might be happening, or a more productive way to use .onComplete, I would appreciate the help. Maybe some help understanding the .setInterval code use, I think if I could force a pause in the code, it would give the sound enough time to play out, and then the .onComplete would work appropriately.
 
Your code will attach all 3 sounds in one go (if "textArray" has all 3 sounds in it) and plays the last one attached from 1 second point. I don't think that's not what you're trying to do.

Let's say your "textArray" consists of the names of the sounds in the order you want them to play. What you should do is attach the first one in the Array and start. Then onSoundComplete, attach the second one and start, and so on forth.

Kenneth Kawamoto
 
What I found out is the onSoundComplete will work in two situations. If I stream in the sounds, it works fine. And I think if I embed the sounds to the timeline, and then use labels to direct the play-order of the sounds, it will work as well. But like you pointed out... embedded sounds on the same point on the timeline will play at the same time, even if you're attempting to circumvent the order of things.

I got the streaming sounds to work - here's a beta version of my flash .swf file ( ... may still be a few bugs to be worked out, and I intend on animating the button labels a bit so that even people who don't read english will be able to use it. I also intend on embedding the sounds and trying the timeline manipulation thing because I don't like the delay between sound bites while streaming.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top