Solved

Music Off and On --MouseOver,MouseOut

Posted on 1997-07-25
3
502 Views
Last Modified: 2011-10-03
             Hi

Could anyone help me with this.
I want musik to be played when "onMouseOver" a link and the
musik should stop when "onMouseOut".
The code I did here below work but when I do "onMouseOut"
I start a where short empty midi-file , to stop the first one.
Couldn't I just stop the first one without start another,
and how?
And what does the parameter "mastersound" in embed tag do?
Without this it doesn't work at all?

Thank you in advanced / Pelle Sweden
(I want to give this question more points but thats all I have)
<HTML>
 <HEAD>
 <TITLE></TITLE>
 </HEAD>

 <SCRIPT LANGUAGE="JavaScript">
  function start() { document.on.play()}
  function stopp() { document.off.play()}
 </SCRIPT>

<BODY>
 <EMBED NAME="on"  SRC="musik2.mid" HIDDEN=true AUTOSTART=false mastersound></EMBED>
 <EMBED NAME="off" SRC="kort.mid"   HIDDEN=true AUTOSTART=false mastersound></EMBED>

 <A HREF="javascript:void(0)"
          onMouseover="start()"
          onMouseOut="stopp()">Music On/Off</A>

 </BODY>
 </HTML>
0
Comment
Question by:PerBoman
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
Trevor013097 earned 50 total points
Comment Utility
Okay try this:-

<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function start()
{
document.the-name.play(false);
}

function stop()
{
document.the-name.play(true);
}
</SCRIPT>


<BODY>

<EMBED SRC="filename.wav" HIDDEN=TRUE AUTOSTART=FALSE NAME="the-name" MASTERSOUND>

<a href="your-link.html"
onMouseover="JavaScript:start();"
onMouseout="JavaScript:stop();">Start Music</A>

</BODY>

</HTML>

This simply changes the play property of the embedded sound when your mouse goes over the link.

Hope this helps
 
0
 

Author Comment

by:PerBoman
Comment Utility
I have tried this, it doesn't work on my computer.
The play function do the same regardless off the parameter
"true" or "false" . Why?
/Pelle Sweden
(Why do you have the parameter false on your function start,
 true seems more logic, but neither want work for me)
0
 
LVL 5

Expert Comment

by:Trevor013097
Comment Utility
Hi Pelle,

Okay the script below works great for me.  It will only work in Netscape 3 or higher and will not work in MSIE 3 or 4, something to do with lack of support for the play() method.

The script uses two functions, one to start and one to stop the music.  The play() part of the start function has the switch false as this tells the music not to loop, if you wanted it to play repeatedly you would replace it with true.

The stop() is used in the second function to stop the music.

<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
function start()
      {
      document.music.play(true);
      }

function stop()
      {
      document.music.stop();
      }
</SCRIPT>

</HEAD>



<BODY>

<EMBED SRC="midis/mission.mid" HIDDEN=TRUE AUTOSTART=FALSE NAME="music" MASTERSOUND>
<BR>
<a href="your-link.html"
onMouseover="start();"
onMouseout="stop();">Mouse Sensitive Music</A>

</BODY>

</HTML>

Hope this helps.

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now