Playing one sound at a time in AS3, called from javascript
I'm working on a site, for kids, which has a small avatar in the corner that talks. The avatar is a flash fi开发者_C百科le and the plan is to determine what it says through a mix of javascript and ajax.
Unfortunately when I make the flash file play an Mp3 file through JavaScript, I can't seem to stop the sound.. so when I keep clicking on a link which causes it to talk, I hear the sound repeated x times.
The odd thing is, when I attach the very same code to a button in flash, there seems to be no such limitation.
It seems as if it won't store anything in global variables when calling from JavaScript.
Any idea what's going on here?
Disclaimer: I'm completely new when it comes to AS3 (and so far, I'm really hating it)
If you're having issues with reliable sound playback, and you're new to AS3, I highly recommend using Matt Przybylski's SoundManager class. It helps to abstract some of the nuances of reliable sound playback in Flash. There shouldn't be any issues with "global variables when calling from JavaScript," but we would need to see some sample code to help debug that.
You could have a Boolean variable in your Flash file that would indicate if the sound is currently playing or not. If the variable is "true", when Javascript asks Flash to play the sound, it wont because it knows the sound is currently playing. Then you can check when the sound is complete, and set the Boolean back to false.
精彩评论