Results 1 to 9 of 9

Thread: 2 onMouseover functions: sound, & rollover

  1. #1
    Join Date
    May 2007
    Posts
    99
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default 2 onMouseover functions: sound, & rollover

    Is there any way to have 2 onMouseover functions together? What I want is a rollover image, and the sound wav. I read in lots of places that this is possible if you put a semicolon in between, but it's not working. Can somebody help me? I had another thread going about the wav but this is a different topic now. There's nothing else on my page so you'll probably detect my fault right away. I'm a beginner, so can someone give me the exact thing to change where my script is wrong? Please?

    Here's my example:
    http://moneytreeaffiliates.com/Practice.htm

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Your example page looks as though it may or may not suffer from other problems. However, there is no limit to the number of function executions that can be performed for a given event. They cannot, of course, directly conflict with each other, but that (other than proper syntax and general coding) is the only consideration. I see you have (from your source):

    Code:
    onMouseOver="EvalSound('sound1');javascript: this.src='images/Adobe_icon_2.bmp';"
    The highlighted bit isn't needed (but shouldn't hurt in most cases). The 'word':

    onMouseOver

    should be all lower case letters for forward compatibility. Other than that, it is just a question of the two functions being valid on their own and compatible with each other.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    May 2007
    Posts
    99
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Hi John.
    I changed the parts you said to. If it's still not working, does that mean the sound and the image rollover are just not compatible with each other? Whichever one I put first is the only one that will work.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Works fine here. There is a slight problem with the image rollover though. The path to the images is wrong:

    Code:
    this.src='images/Adobe_icon_2.bmp'
    Opera doesn't seem to like the mouse down sound, but FF and IE are OK with it. The embed tag, which generally works well for sound in this case, is invalid, but I'm not going to worry about that right now. The sound playing function, though working, is poorly written, and can be reused (you only need one). Try this out:

    Code:
    <html>
    <head>
    <title>New Page 1</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    
    function EvalSound(soundobj) {
    document[soundobj].Play();
    }
    
    </script>
    </head>
    <body>
    <embed src="Wav_1.wav" autostart=false width=0 height=0 name="sound1"
    enablejavascript="true">
    <embed src="Wav_2.wav" autostart=false width=0 height=0 name="sound2"
    enablejavascript="true">
    <p align="center"><a href="http://google.com"><img border="0"
    src="Adobe_icon.gif"
    onmouseover="EvalSound('sound1');this.src='Adobe_icon_2.bmp';"
    onmouseout="this.src='Adobe_icon.gif';"
    onmousedown="EvalSound('sound2');this.src='Adobe_icon.gif';"
    width="32" height="32"></a></p>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    May 2007
    Posts
    99
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Ohmygosh I feel so stupid. I had the image in the wrong place. LoL

    Ok, I fixed everything you said and now voila! Thank you!!!
    Last edited by nycguurl; 11-17-2007 at 05:45 PM.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You didn't really do what I did, but you are getting closer. The main difference now is that your onmouseout image is the same as your onmouseover image. It should be the same as the original image. Also, although you removed the second sound function, you didn't upgrade the one that you kept.

    I played around with this idea a bit more and discovered that the reason Opera doesn't like the onmousedown sound has something to do with the sound file itself, a different wav file might work onmousedown with Opera. I also made an improvement to the sound function to prevent an error message for browsers that don't support it. And, you really should use the type attribute with the script tag:

    Code:
    <script type="text/javascript">
    function EvalSound(soundobj) {
    if(typeof document[soundobj].Play != 'undefined')
    document[soundobj].Play();
    }
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    May 2007
    Posts
    99
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Yikes, you are right, I didn't do exactly what you said. I must have missed that. I am properly chastised. LoL
    Also, the image mouseovers are in the right places now.

    When you said:
    Also, although you removed the second sound function, you didn't upgrade the one that you kept.
    What do you mean?
    Is it upgraded now with the code you gave me?

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by nycguurl View Post
    Is it upgraded now with the code you gave me?
    Yep! A lot of this stuff has nothing to do with javascript exactly. At times it would help to have a look at what you are telling the browser to do, and see if it's what you want to be telling it. For example, the onmousedown image path is still (or again) incorrect. That's just a proofreading/typo sort of error though. Nothing to get too excited about.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    May 2007
    Posts
    99
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default

    Umm.. I get excited about everything, LoL
    I better go check it out...

    Ok, I'm back, and it's fixed.
    By the way, those yucky sounds are just for practice, not the real ones I'm using.
    I'll be back if I need to as I incorporate this onto my real page now.
    Last edited by nycguurl; 11-18-2007 at 09:05 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •