By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,910 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,910 IT Pros & Developers. It's quick & easy.

How to select play 1 of 5 songs using Javascript?

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Con <co******@runbox.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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.

--
S.C.

Jul 23 '05 #2

P: n/a
Con
Hi, is there a 'this' pointer or something that they can reference
within these blocks?

Thanks,

-Conrad

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.