Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sound on button 1

Status
Not open for further replies.

ToddWW

Programmer
Mar 25, 2001
1,073
US
In my OVER state frame for a button symbol, I have selected a 1 second sound (engine idling). I select the LOOP option so the engine idling sound plays continuously. This all works fine when the user hovers over the button. Now, is there an easy way to stop the sound when the user moves away or clicks on the button. I am still a little new to Flash. I see that I cannot put ActionScript in any of the button symbol's frames. I assume I could put the ActionScript in the object that creates my Hit Area ?? Anyways, the effect I am looking for is to have an engine idling sound play as long as the mouse is over the button and stop when the mouse moves away from the button or if the button is clicked.

Any ideas would be appreciated.

Todd
 
The following script does what you after. In this example "buttonInstance" is the name of your Button instance, and "engine.mp3" is the Linkage ID of your sound in the Library.
Code:
// Main Timeline 
var snd:Sound = new Sound(buttonInstance);
snd.attachSound("engine.mp3");
buttonInstance.onRollOver = function():Void  {
	snd.start();
};
buttonInstance.onRollOut = buttonInstance.onPress=function ():Void {
	snd.stop();
};

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top