PDA

View Full Version : Problem with sound rollover playing repeatedly...


embersyc
10-10-2009, 08:05 PM
Here is my class, but when I rollover the button, especially near the edge of the button the sound plays continuously. I have tried to set up a boolean variable and set it true after the sound plays and false on mouse out and only play when false, but that didn't work either... I was thinking about setting up a timer to handle it, but I wanted to make sure there wasn't something simpler I was missing first.

package {

import flash.display.MovieClip;
import flash.events.*;

public class BlankButton extends MovieClip {

private var clickSound:Click_Sound = new Click_Sound();
private var blipSound:Blip_Sound = new Blip_Sound();

public function BlankButton(txt:String, xLoc:Number, yLoc:Number) {

this.x = xLoc;
this.y = yLoc;
this.btn_txt.text = txt;
this.buttonMode = true;
this.addEventListener(MouseEvent.MOUSE_OVER, mover);
this.addEventListener(MouseEvent.MOUSE_OUT, mout);
this.addEventListener(MouseEvent.MOUSE_DOWN, mdown);
}

private function mover(e:MouseEvent):void
{
this.gotoAndStop(2);
blipSound.play();
}
private function mout(e:MouseEvent):void
{
this.gotoAndStop(1);
}

private function mdown(e:MouseEvent):void
{
this.gotoAndStop(3);
clickSound.play();
}



}
}

RogerClark
10-10-2009, 08:49 PM
I could be mistaken, but if you look in the livedocs the default for the sound.play is to loop indefinately

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/media/Sound.html#play%28%29

i.e. loop defaults to 0

Try setting loop to 1

i.e.

blipSound.play(0,1);
etc

embersyc
10-10-2009, 08:53 PM
Not sure if that would've worked, I solved it by switching from MOUSE_OVER TO ROLL_OVER, and adding the boolean back in.

This works:

package {

import flash.display.MovieClip;
import flash.events.*;

public class BlankButton extends MovieClip {

private var clickSound:Click_Sound = new Click_Sound();
private var blipSound:Blip_Sound = new Blip_Sound();
private var soundPlayed:Boolean = false;

public function BlankButton(txt:String, xLoc:Number, yLoc:Number) {

this.x = xLoc;
this.y = yLoc;
this.btn_txt.text = txt;
this.buttonMode = true;
this.addEventListener(MouseEvent.ROLL_OVER, mover);
this.addEventListener(MouseEvent.ROLL_OUT, mout);
this.addEventListener(MouseEvent.MOUSE_DOWN, mdown);
}

private function mover(e:MouseEvent):void
{
this.gotoAndStop(2);
if(!soundPlayed) {
blipSound.play();
soundPlayed = true;
}
}
private function mout(e:MouseEvent):void
{
this.gotoAndStop(1);
soundPlayed = false;
}

private function mdown(e:MouseEvent):void
{
this.gotoAndStop(3);
clickSound.play();
}



}
}