Embeding help

liunx

Guest
I am trying to make it so that whenever a person moves there mouse over an image on a page that I am making, a sound will go off. But I have no clue as to how to do this. Someone told me to put it in the 'Alt=' part of the image tag, but I either did not work, or I coded it improperly. I am having doubts as to whether this is even possible with HTML, and thinking it might be done in Java. Any help would be great.<!--content-->Ok the alt part of the img tag is just a title like when someone puts a mouse over its going to put a tooltip on there, I reccomend using that it is cool. The sound will use java script and an array in your head. Ill get back to you in a second with the code you will need<!--content-->Put this in your head<br />
<head><br />
var aySound = new Array();<br />
// Below: source for sound files to be preloaded<br />
aySound[0] = "yoursound.wav or mp3 or midi or whatever";<br />
<br />
<br />
// DO NOT edit below this line<br />
document.write('<BGSOUND ID="auIEContainer">')<br />
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;<br />
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;<br />
ver4 = IE||NS? 1:0;<br />
onload=auPreload;<br />
<br />
function auPreload() {<br />
if (!ver4) return;<br />
if (NS) auEmb = new Layer(0,window);<br />
else {<br />
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";<br />
document.body.insertAdjacentHTML("BeforeEnd",Str);<br />
}<br />
var Str = '';<br />
for (i=0;i<aySound.length;i++)<br />
Str += "<EMBED SRC='http://www.webdeveloper.com/forum/archive/index.php/"+aySound+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"<br />
if (IE) auEmb.innerHTML = Str;<br />
else {<br />
auEmb.document.open();<br />
auEmb.document.write(Str);<br />
auEmb.document.close();<br />
}<br />
auCon = IE? document.all.auIEContainer:auEmb;<br />
auCon.control = auCtrl;<br />
}<br />
function auCtrl(whSound,play) {<br />
if (IE) this.src = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/play">http://www.webdeveloper.com/forum/archi ... x.php/play</a><!-- m -->? aySound[whSound]:'';<br />
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"))<br />
}<br />
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }<br />
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }<br />
//--><br />
</script><br />
</Head><br />
<br />
ok these are your event handlers, modify them all you want<br />
<body><br />
<br />
<A HREF=http://www.webdeveloper.com/forum/archive/index.php/"YourPage.html" onMouseOver="playSound(0)" onMouseOut="stopSound(0)">Move mouse over to play sound</A><br />
<br />
<br />
enjoy :D<!--content-->I tried that, but I get an error every time I move me mouse over the desired area. I even made a page solely with the code, and all I got was a white screen, all of the code that you told me in black text, and the link at the bottom.<!--content-->Make sure that sound object exists. Like make sure your path is correct and that that sound is uploaded.<!--content-->Give me a link to your site. Also what browser are you using?<!--content-->Unfortunatly I'm just messing around with notepad, and I do not have a website. I am, however, attaching the sound and html file which I am using. Also I am using the newest internet explorer browser.<!--content-->Here is the text file I am using. The sound file is in the folder in which I placed the html file. I am using Internet Explorer.<!--content-->Ok and you have this saved as an html file on your desc top or somplace and you are opening it with internet explorer. Try specifying the full path to the sound, Im not sure if you need to do that but I have had to do that with other scripts in the past, I cant seem to find anything else that might hurt it. Huh this is pretty strange alright because that code works just fine for me on another site of mine. Please discribe the error message you get.<!--content-->It says:<br />
Line: 45<br />
Char: 1<br />
Error: Object Expected<br />
Code:0<br />
then the URL<br />
The sound file path should be fine as I have used it before with other HTML files in the same folder and they have worked perfectly.<!--content-->But this is a java script. You might need to do the full path im not sure with this one. I would not thing you would have to but I have seen times where you do. The code looks like it should be working. Its a bad character somewhere from the looks of your error. Ask dave he seems to be a big authority on java script, he will be able to help a lot more then me.<!--content-->That looks like fun, PeOfEo - I always thought that was neat but never took the time to look up the instructions - thank you for posting that code! Hope you don't mind I grabbed it, too - I love trying all this stuff and will give it a go tomorrow, if not later tonight. If I can find this thread, I'll let you know if it worked for me or not, okay? I have to find some sound files, too - think it's going to be a "play night". :D<!--content-->lol ok, I just grabbed that code off of javascriptkit.com lol, does not bother me if you use it.<!--content-->:D Thanks, PeOfEo - think I'll check that site out! :D<!--content-->Rntaboy, are you still having problems with this script? It seems to work fine for me in IE6 after I added a <script language="javascript" type="text/javascript"> tag to the top of the script.<!--content-->Pyro thanks a ton, that fixed everything. Don't you hate it when you make such stupid little mistakes. Thanks a ton PeoFEo for the bulk of the code. It all works now, thanks.<!--content-->OH JEESE I KNEW I WAS FORGETTING SOMETHING. Its always the stupid mistakes that getcha lol.<!--content-->Its always the stupid mistakes that getcha <br />
<br />
:D A-men to that!!! Hehe...on my new site I switched my background color and text color - just swapped them and then couldn't figure out why my text wouldn't show up on the new color. I forgot to change it in the CSS file....<br />
<br />
DOH IS ME!!! LOL :p<!--content-->I almost forgot! HELP!! :eek: Can anyone clue me in on do how to get this to work with buttons? Tx!<!--content-->it should work the same way are you using image buttons like a link with an image or a command button?<!--content-->Okay, this is probably me screwing up again, as I've never done this before, so when you're done chuckling...:D <br />
<br />
Here is the way I coded it...<br />
<br />
<A HREF=http://www.webdeveloper.com/forum/archive/index.php/"#" onMouseOver="playSound(0)" onMouseOut="stopSound(0)"><img src="btn.gif" width="146" height="46" alt="Button" border="0"></A><br />
<br />
This site isn't online yet and there are no active pages, either, but I thought maybe I could make it work - and I do have the sound file in the folder. :) I also added that little snippet of code that needed to be put on the top and I did change the name of the source in the header code, too - WAH I still don't get it! <br />
<br />
:confused:<!--content-->Hi all!!<br />
<br />
I'm trying to use the same sound script in a file that I'm working with but I don't know how to fix it???<br />
<br />
Is there anyone who can look at this scrip and want to help me!? <br />
<br />
Would really appreciate it if you could help me with <br />
this big problem. <br />
Here is the file (with the sound script) without the sound files:<!--content-->
 
Back
Top