Solved

Music Off and On --MouseOver,MouseOut

Posted on 1997-07-25
3
531 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
ID: 1268724
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
ID: 1268725
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
ID: 1268726
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

756 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