views:

31

answers:

2

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)

+1  A: 

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.

sunetos
Well the absolute weird thing is that now that I ran my testing html page a day later, without modifying it, it works perfectly.. So I'm somewhat confused about what happened.. I'll check out the link, thanks!
Sander van Rossen
Whenever you're working with javascript and/or flash development, be aware of browser caching. Always clear your cache or shift-refresh to get the latest swf/js when you build. It's possible your issue was due to loading a cached earlier build of the swf.
sunetos
A: 

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.

__dominic
That's the first thing I tried, but it didn't work. Oddly enough the same unmodified code works a day later, so I'm thinking it may have been a browser caching issue or something. Thanks anyway!
Sander van Rossen