CactusZeus Chonch CactusZeus Chonch - 1 year ago 98
HTML Question

HTML5 flash canva can't stop my sound with "mouseout" function

I found on the Adobe forum an answer to some of my questions about coding MouseOver in "flash html5 mycanva.fla" to trigger a sound when hovering a button. see here

The thing is, i'm stuck with the "MouseOut function" when it comes to stop the sound played when you MouseOut the button !

The cherry on top would be to pause the sound on mouseout and playit from the point it was paused when mouseover again. But i don't want to appear too greedy ;-)

Here's the code i used in my_flash_canva.fla:

var frequency = 3;
this.mybutton.addEventListener("mouseover", fl_MouseOverHandler);

function fl_MouseOverHandler(){
//linked sound from library by dble clicking on it and named a link in the blank area.Indeed, the action script panel in "mysound" properties panel is greyed..
//works like a charm

this.mybutton.addEventListener("mouseout", fl_MouseOutHandler);
function fl_MouseOutHandler() {
// doesn't work

Using flash pro cc 2014. I guess i must be missing something or bad syntaxing but in my mind what does work with playSound("xxx") should work with stopSound("xxx") . But apparently it 's not that simple. Any clue is welcome, I would be grateful. Thanx a lot.


Answer Source

You can not stop a sound that way. What is stopSound()? If you look at your exported HTML, the playSound is a function that plays a sound using an ID. It should return an instance that you can control. You have to store that instance, and call stop() on it.

var sound;
function fl_MouseOverHandler(){  
    sound = playSound("monstres"); 

this.mybutton.addEventListener("mouseout", fl_MouseOutHandler);  
function fl_MouseOutHandler()  {  

You will have to modify the generated playSound method in the HTML to return the instance that is played, since it currently does not:

function playSound(id, loop) {
    return, createjs.Sound.INTERRUPT_EARLY, 0, 0, loop);

This is a good thing to report to Adobe, as it should do that already. I have logged a bug to do that.

[Edit: This fix was included in Adobe Animate]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download