Sander van Rossen
Sander van Rossen

Reputation: 13

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 file 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)

Upvotes: 1

Views: 311

Answers (2)

dotminic
dotminic

Reputation: 1145

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.

Upvotes: 0

sunetos
sunetos

Reputation: 3508

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.

Upvotes: 1

Related Questions