ImpInTraining
Programmer
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
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