Flash Tutorials
& Resources
Dreamweaver
Tutorials
Fireworks &
Illustrator Tutorials
Photoshop
Tutorials
Web Design
Tutorials & Resources
CSS
Tutorials
CorelDraw
Tutorials
You are here : : Home > Free Resources > Dreamweaver Tutorials > Play Sound  

 

Featured Fireworks & Dreamweaver Template

Real Estate Template 10
Real Estate
$49.95

Play Sound on Mouseover or MouseClick

Play sound, music on Rollover, on Click or on Page Load using Dreamweaver Behaviors

Sample: Click Here to Play Sound

Learn how to use Dreamweaver Behaviors to Play Sound in 2 quick steps

  1. The first step is to create a link for the sound to be played on Rollover or on Click. You can make a simple text link with the '#' symbol.
  2. The next step is to add a behavior to the link. Open the Behaviors panel by clicking on Windows/Behaviors and click on the '+' symbol in the Behaviors Panel. Click on 'Play Sound'. Browse to find the sound you want to play and click on OK.

Note: If you want the music to play on some other event, go back to the behaviors panel and in the events drop down menu choose another event e.g. If you want the music to play on Rollover then you have to choose onMouseOver

Javascript Code

<script language="JavaScript">
<!--
function MM_controlSound(x, _sndObj, sndFile) { //v3.0
var i, method = "", sndObj = eval(_sndObj);
if (sndObj != null) {
if (navigator.appName == 'Netscape') method = "play";
else {
if (window.MM_WMP == null) {
window.MM_WMP = false;
for(i in sndObj) if (i == "ActiveMovie") {
window.MM_WMP = true; break;
} }
if (window.MM_WMP) method = "play";
else if (sndObj.FileName) method = "run";
} }
if (method) eval(_sndObj+"."+method+"()");
else window.location = sndFile;
}
//-->
</script>

Dreamweaver also generates the following code that embeds the sound file within the page

<embed name='CS1022563046202' src='sound.wav' loop=false
autostart=false MASTERSOUND hidden=true width=0 height=0>
</embed>
This can be included towards the end of the page.

HTML Code

<a href="#" onClick="MM_controlSound('play','document.CS1022563046202','sound.wav')">Click
Here to Play Sound</a>
The above code is taken from Macromedia Dreamweaver 4.0

Note: Make sure a sound file called 'sound.wav' is included in your local folder.

 



No portion of these materials may be reproduced in any manner whatsoever, without the express written consent of Entheos. Any unauthorized use, sharing, reproduction or distribution of these materials by any means, electronic, mechanical, or otherwise is strictly prohibited.