This content has been marked as final. Show 11 replies
use the attach code option to display your actionscript. otherwise, your code is apt to be mangled by this forum. your code is difficult to read.
the fatal errors are a failure to clear that interval before it's set which can lead to more than one setInterval being called before previous ones are cleared and the failure to pass "this" to waitForSound().
anyway, this problem is not that complex. just check to see if a sound is playing when a new sound is called for (by check soundPlaying) and if it is, define nextIndex (the index of the next sound that should play):
Thanks very much for the help, but I still have a couple more questions.
Can you explain more about "failure to pass "this" to waitForSound()."? How should I do that?
Also, if the sounds are loaded with the code you gave, will the movie wait at that point until all the sounds have loaded, or will it continue playing while the sounds continue loading? I want the movie to continue while the sounds load in the background, so I can then call them as needed.
P.S. Thanks for the tip on attach code. I went back and fixed that.
no, you'll need to use something (like your onLoad method) to ensure all your sounds are loaded before proceding.
when setInterval() calls a function "this" in the function is undefined unless you specifically pass that reference to the function. to do that you should use:
Well, thank you again for your help, but it's still not working. I now have the code as below.
The output is:
loading sound 1: sounds/01_01.mp3
loading sound 2: sounds/01_02.mp3
loading sound 3: sounds/01_03.mp3
...etc...loading sound 24: sounds/01_24.mp3
The trace("waiitng") never appears. And it seems the main timeline remains stopped, because the movie never runs to its end.
there are, at least, two issues with your code.
you have one playMe() method for each sound object (and that's unneeded) and you're using this.start() where "this" refers to the timeline that contains that code, not to the sound object.
That was really helpful! Of course you were right about all those playMe() functions. I pulled that out as a separate function. Also, the "this" was incorrect. I pulled the waitForSound() function out also. The new code WORKS!
In the frame where I want the sound to start, i now have "playMe(1);" or "playMe(2);" etc.
I do have one more question. The business of passing the soundNum parameter to playMe() and then having to store that in _root. nextSound so that waitForSound() knows what sound to play when the interval clears... that seems clumsy to me. I mean, it works, but it seems inelegant. Is there some way for playMe to pass the soundNum to waitForSound? Something like:
soundInterval = setInterval(tl,"waitForSound(soundNum)", 10);
... but that doesn't work.
yes, you can pass an unlimited number of parameter to the function called by setInterval(). those parameters should be listed after the frequency parameter:
Excellent! Thank you, I have updated it and it works perfectly.
One other thing and then I will stop asking questions, I promise - you must have better things to do than this! Because some of the sound files may be quite large, and they can be played in an unpredictable order, I need to check that a sound has been loaded before trying to play it. Especially over a slow Internet connection.
I updated the script to cover this case, but it's hard to test because the sounds load almost instantly from my hard drive. Can you take a look at the script and see if it looks correct, or do you have any ideas for testing it?
click on control/test movie. in the test environment click view/download settings and click the download speed you want to test. then click view/simulate download to test.
Thank you. Now another problem: the movie plays fine and loads the sounds when I try it in the Flash authoring environment, or when I play the swf in the Flash Player.
But when I place the SWF in an HTML document (using DreamWeaver). it plays with no sound. The mp3 files are all in the "sounds" directory, which is inside the "flash" directory, where the swf is located.
This happens when I try it on my hard drive as well as when it's over the internet. What can the problem be?