Button sound on mouseover

zerog
zerog used Ask the Experts™
on
Greetings.

How do I add a 'click' sound on mouseover that will apply to all buttons in my flex project? Looking forward to your responses.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Im not a flex expert but the following forum seems to answer your question.
http://www.actionscript.org/forums/showthread.php3?t=97253
Commented:
The above code is done in AS2 and it won't work in Flex environment.

You can do something like this.

CyanBlue
<fx:Script>
	<![CDATA[
	
		private function onRollOver(e:MouseEvent):void
		{
			var sound:Sound = new Sound(new URLRequest("path/to/sound.mp3"));
			sound.play();
		}
		
	]]>
</fx:Script>

<s:Button width="100" height="50" label="ROLL OVER ME" mouseOver="onRollOver(event)" />

Open in new window

Author

Commented:
CyanBlue I've tried your response but get the following error, maybe I'm implementing it incorrectly.

Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
      at outreach/onRollOver()[C:\outreach\src\outreach.mxml:35]
      at outreach/___outreach_Button19_mouseOver()[C:\outreach\src\outreach.mxml:290]


This is the code for one of my many buttons in the interface

<s:Button includeIn="State1" width="158" height="170"
                    label="Learn the link"
                    color="#FFFFFF" fontSize="22" horizontalCenter="310" skinClass="skins.TransBtn2"
                    verticalCenter="-2"
                    click="currentState='interface1'"/>

Author

Commented:
Got it working. My path to the sound file was incorrect. Thank you for a really simple solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial