How to select play 1 of 5 songs using Javascript?

C

Con

Hi, I'm getting the following error message in the JavaScript console:

Error: mus has no properties
Source File: file:///G:/temp/cafedub.htm
Line: 35

Now, I would like to script to work in both IE 6 and Netscape 7. The
goals of the script are as follows:

o when a music image is clicked, please the associated music without
looping
o if the same image is clicked again, then that music stops playing
o if another image is clicked, then it should stop all others and play
the
currently selected music link
o the script should play in the background while the page is displayed

BEGIN SCRIPT:

<script>

var musi;
var mus;
var songs = new Array();

songs[0] = "mp3/burt_lick_the_lishna_weenay.mp3";
songs[1] = "mp3/mouse_cant_tap.mp3";
songs[2] = "mp3/cool_and_keen,mp3";
songs[3] = "mp3/hollywood_poser_blues.mp3";
songs[4] = "mp3/suction_boy.mp3";

var isOn = new Array();

isOn[0] = false;
isOn[1] = false;
isOn[2] = false;
isOn[3] = false;
isOn[4] = false;

function mus1( musicNumber )
{
musi = songs[ musicNumber ];

if ( !isOn[ musicNumber ] ) {
mus.innerHTML="<embed src="+musi+" loop=-1>";
isOn[ musicNumber ] = true;
}
else {
mus.innerHTML = "";
isOn[ musicNumber ] = false;
}
}

document.write("<span id='mus'
style='position:absolute;top:-90000'><embed src="+musi+" width=0
height=0 loop=-1></span>");

END SCRIPT:

BTW, my links are developed as follows:

<a id="mus" href="javascript:void(0)" onclick="mus1( 2 )"><img
src="sound.gif"
width="16" height="16" border="0"></a>

If anyone has any ideas as to how to resolve this issue, please post to
the group.

Thanks in advance,

-Conrad
 
S

Stephen Chalmers

Con said:
Hi, I'm getting the following error message in the JavaScript console:

Error: mus has no properties
Source File: file:///G:/temp/cafedub.htm
Line: 35

Now, I would like to script to work in both IE 6 and Netscape 7. The
goals of the script are as follows:

o when a music image is clicked, please the associated music without
looping
o if the same image is clicked again, then that music stops playing
o if another image is clicked, then it should stop all others and play
the
currently selected music link
o the script should play in the background while the page is displayed

BEGIN SCRIPT:

<script>

var musi;
var mus;
var songs = new Array();

songs[0] = "mp3/burt_lick_the_lishna_weenay.mp3";
songs[1] = "mp3/mouse_cant_tap.mp3";
songs[2] = "mp3/cool_and_keen,mp3";
songs[3] = "mp3/hollywood_poser_blues.mp3";
songs[4] = "mp3/suction_boy.mp3";

var isOn = new Array();

isOn[0] = false;
isOn[1] = false;
isOn[2] = false;
isOn[3] = false;
isOn[4] = false;

function mus1( musicNumber )
{
musi = songs[ musicNumber ];

if ( !isOn[ musicNumber ] ) {
mus.innerHTML="<embed src="+musi+" loop=-1>";
isOn[ musicNumber ] = true;
}
else {
mus.innerHTML = "";
isOn[ musicNumber ] = false;
}
}

document.write("<span id='mus'
style='position:absolute;top:-90000'><embed src="+musi+" width=0
height=0 loop=-1></span>");

END SCRIPT:

BTW, my links are developed as follows:

<a id="mus" href="javascript:void(0)" onclick="mus1( 2 )"><img
src="sound.gif"
width="16" height="16" border="0"></a>

If anyone has any ideas as to how to resolve this issue, please post to
the group.

Thanks in advance,

-Conrad

The variable 'mus' has nothing assigned to it, therefore the error message
is correct.
 
C

Con

Hi, is there a 'this' pointer or something that they can reference
within these blocks?

Thanks,

-Conrad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top