How to select play 1 of 5 songs using Javascript?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Con

    #1

    How to select play 1 of 5 songs using Javascript?

    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_l ishna_weenay.mp 3";
    songs[1] = "mp3/mouse_cant_tap. mp3";
    songs[2] = "mp3/cool_and_keen,m p3";
    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="javascrip t: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

  • Stephen Chalmers

    #2
    Re: How to select play 1 of 5 songs using Javascript?

    Con <conradwt@runbo x.com> wrote in message
    news:1109307565 .723973.138690@ f14g2000cwb.goo glegroups.com.. .[color=blue]
    > 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_l ishna_weenay.mp 3";
    > songs[1] = "mp3/mouse_cant_tap. mp3";
    > songs[2] = "mp3/cool_and_keen,m p3";
    > 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="javascrip t: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
    >[/color]

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

    --
    S.C.



    Comment

    • Con

      #3
      Re: How to select play 1 of 5 songs using Javascript?

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

      Thanks,

      -Conrad

      Comment

      Working...