Hyperlink message words or Icon

G

Guest

I have a funny story but I want the readers to finish reading before they have to
_Click Me Now_ or an Icon to open up my laughing sound.

The document file and sound (.wav) file are ready in a folder. I don't want to make
background sound for my page. Using FP-Office xp. I did tried Ctrl+K but not
successful.

Please help me,
Rino
 
T

Trevor L.

I have a funny story but I want the readers to finish reading before
they have to _Click Me Now_ or an Icon to open up my laughing sound.

The document file and sound (.wav) file are ready in a folder. I
don't want to make background sound for my page. Using FP-Office xp.
I did tried Ctrl+K but not successful.

Please help me,
Rino

Try this

Between <head> and </head>:
<script type="text/javascript">
function playSound(fname)
{
if (!fname)
fname = "audio/minuet.mid"
var x = document.getElementById("sound")
x.innerHTML = (!x.innerHTML ) ? '<embed src="' + fname + '" loop=false
autostart=true hidden>' : ''
}
</script>

Between <body> and </body>:
<!-- Place the text you want readers to see here -->

<!-- ending here -->
<span id="sound"></span>
<input type="button" value="Play/Stop
Music" onclick="playSound()"/>

The name of your .wav file should replace that after fname=
Change the text in the button after value= to what you want, e.g. "Click Me
Now"
 
G

Guest

Hi Trevor L.,
Thanks -- but it didn't work on mine. My audio file location is: G:\My
Project\Final\Worst Funny Story\sound001.wav in a folder with document file. I did
tried that actual location and still not working.

Your JavaScript gives 2 error message; one on clicking for Preview mode --- it says
Line 9, Char 1, Sysntax error, Code 0 and the other one when I click the button --- it
says line 84, Char 1, Object Expected, Code 0. Only the 2nd errors always come out on
my Browser.

Can you please check all my insertions if correct --- especially my 2nd one. Only the
affected html codes were enclosed below.

Thank You Very Much!
Rino


<head>
<script type="text/javascript"><BR>function playSound(fname)<BR>{<BR> if
(!fname)<BR> fname="sound001.wav"<BR> var x =
document.getElementById("sound")<BR> x.innerHTML = (!x.innerHTML ) ? '<embed
src=="' + fname + '" loop=false <BR>autostart=true hidden>' :
''<BR>}<BR>
</script>
</head>
<body background="purpl072.jpg">
<body>
<!-- Place the text you want readers to see here --><BR>
<div>
<font face="Arial" size="5"><strong>Worst First Date Story</strong> -
Hilarious<b><i>!</i></b></font></div>
<div>
<br><p>
<font face="Arial" size="4">This is probably the funniest date story ever, first date
or not<i>!! </i> </font>
<p>
<font face="Arial" size="4">We all have bad dates.. but this takes the cake. This
just tells you how tough it is to be single nowadays. This was on the &quot;Tonight
Show&quot; with Jay Leno. Jay went into the audience to find the most embarrassing
first date that a woman ever had. The winner described her worst first date experience.
There was absolutely no question as to why her tale took the prize! </font>
</div>
<div>
<font face="Arial" size="4">"Obviously, as hysterical as the situation was, we also
were faced with a real problem. We both agreed it would need something hot to free;my
chilly buttock from the grip of the icy metal! Thinking about what had gotten into this
predicament in the first place, both quickly realized that there was only one way to
get me free. So, as I looked the other way, my first-time date proceeded to unzip his
pants and pee my clean butt off the fender. Oh Boy..."</font>
<input type="button" value="Play Music Now" onclick="playSound()"/><BR><BR>
<!-- ending here -->



I have a funny story but I want the readers to finish reading before
they have to _Click Me Now_ or an Icon to open up my laughing sound.

The document file and sound (.wav) file are ready in a folder. I
don't want to make background sound for my page. Using FP-Office xp.
I did tried Ctrl+K but not successful.

Please help me,
Rino

Try this

Between <head> and </head>:
<script type="text/javascript">
function playSound(fname)
{
if (!fname)
fname = "audio/minuet.mid"
var x = document.getElementById("sound")
x.innerHTML = (!x.innerHTML ) ? '<embed src="' + fname + '" loop=false
autostart=true hidden>' : ''
}
</script>

Between <body> and </body>:
<!-- Place the text you want readers to see here -->

<!-- ending here -->
<span id="sound"></span>
<input type="button" value="Play/Stop
Music" onclick="playSound()"/>

The name of your .wav file should replace that after fname=
Change the text in the button after value= to what you want, e.g. "Click Me
Now"
 
T

Trevor L.

Hi Trevor L.,
Thanks -- but it didn't work on mine. My audio file location is: G:\My
Project\Final\Worst Funny Story\sound001.wav in a folder with
document file. I did tried that actual location and still not working.

Your JavaScript gives 2 error message; one on clicking for Preview
mode --- it says Line 9, Char 1, Sysntax error, Code 0 and the other
one when I click the button --- it says line 84, Char 1, Object
Expected, Code 0. Only the 2nd errors always come out on my Browser.

Can you please check all my insertions if correct --- especially my
2nd one. Only the affected html codes were enclosed below.

Thank You Very Much!
Rino

This is my corrected code

The main point is that <BR> should not be used in a fucntion
I also changed most <div>s to <p>s and closed the paras with </p>.
<span source ="sound"> was also missing. This caused the object expected
error.

As for the audio, when I made it a reference on my hard disk, it worked but
asked for an ActiveX control - I don't know why as I have "Allow active
content" ticked!!

You will have to make the reference relative if you are putting this on a
web server.
e.g. my website is tandcl.homemail.com.au and the home page is
tandcl.homemail.com.au/index.html
so my audio is
tandcl.homemail.com.au/audio/minuet.mid

BTW, you left out a vital para. in the joke. I assume the woman somehow
managed to lean up against a frozen car with a bare backside (perhaps they
were enagaged in a bit of outdoor sex) YES/NO?

Which makes me wonder what the tune is!

CODE FOLLOWS
<head>
<script type="text/javascript">
function playSound(fname)
{
if (!fname)
// fname="sound001.wav"
fname = "audio/minuet.mid"
var x = document.getElementById("sound")
x.innerHTML = (!x.innerHTML ) ? '<embed src="' + fname + '" loop=false
autostart=true hidden>' : ''
}
</script>
</head>
<body background="purpl072.jpg">
<!-- Place the text you want readers to see here -->

<p>
<font face="Arial" size="5">
<strong>Worst First Date Story</strong> - Hilarious<b><i>!</i></b>
</font>
</p>

<p>
<font face="Arial" size="4">This is probably the funniest date story ever,
first date
or not<i>!! </i>
</font>
</p>

<p>
<font face="Arial" size="4">We all have bad dates.. but this takes the cake.
This
just tells you how tough it is to be single nowadays. This was on the
&quot;Tonight
Show&quot; with Jay Leno. Jay went into the audience to find the most
embarrassing
first date that a woman ever had. The winner described her worst first date
experience.
There was absolutely no question as to why her tale took the prize!
</font>
</p>

<p>
<font face="Arial" size="4">"Obviously, as hysterical as the situation was,
we also
were faced with a real problem. We both agreed it would need something hot
to free;my
chilly buttock from the grip of the icy metal! Thinking about what had
gotten into this
predicament in the first place, both quickly realized that there was only
one way to
get me free. So, as I looked the other way, my first-time date proceeded to
unzip his
pants and pee my clean butt off the fender. Oh Boy..."
</font>

<span id="sound"></span>
<input type="button" value="Play Music Now" onclick="playSound()"/>
<!-- ending here -->
</body>
</html>
 
G

Guest

Hi Trevor L.
The answer is NO! LOL, GT because PRW:
http://www.webopedia.com/quick_ref/textmessageabbreviations.asp
Here's my complete html code, I referred my sound to my actual PC location to test it.
Does it required 3 times for sound location? And still no sound effect heard. Can I use
Rich Text here to point emphasis so we can undertand well? Can you also insert
background music then when I press the Sound Effect button the music will stop playing
and sound effect come out. Can you also make the button follow scaleable text?

BTW, hope you uses F3 then input my name to find my thread faster.

I really appreciate your kind helps. ---Rino

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Worst Funny Story</title>
<head><BR>
<script type="text/javascript">
function playSound(fname)
{
if (!fname)
// fname="G:\My Project\Final\Worst Funny Story\sound001.wav"
fname = "G:\My Project\Final\Worst Funny Story\sound001.wav"
var x = document.getElementById("G:\My Project\Final\Worst Funny Story\sound001.wav")
x.innerHTML = (!x.innerHTML ) ? '&lt;embed src="' + fname + '" loop=false
autostart=true hidden&gt;' : ''
}
</script>
</head>
<body background="purpl072.jpg">
<body>
<p>
<font face="Arial" size="5"><strong>Worst First Date Story</strong> -
Hilarious<b><i>!</i></b></font></p>
<p>
<br><p>
<font face="Arial" size="4">This is probably the funniest date story ever, first date
or not<i>!! </i> </font>
<p>
<font face="Arial" size="4">We all have bad dates.. but this takes the cake. This
just tells you how tough it is to be single
nowadays. This was on the &quot;Tonight Show&quot; with Jay Leno. Jay went into the
audience to find the most
embarrassing first date that a woman ever had. The winner described her worst first
date experience. There
was absolutely no question as to why her tale took the prize! </font>
</p>
<p>
<font face="Arial" size="4">"It was midwinter... snowing and quite cold... and the
guy had taken me skiing in
the mountains outside Salt Lake City, Utah." </font>
</p>
<p>
<font face="Arial" size="4">"It was a day trip (no overnight). We were strangers,
after all, and truly had
never met before. The outing was fun but relatively uneventful until they were headed
home late that
afternoon. We were driving back down the mountain, when I gradually began to realize
that I should not have
had that extra drinks." </font>
</p>
<p>
<font face="Arial" size="4">"We were about an hour away from anywhere with a rest
room and in the middle of
nowhere!&nbsp;My companion suggested to try to hold it, which I did for a while.
Unfortunately, because of the
heavy snow and slow going, there came a point where I told him that he had better
stop and let me pee beside
the road, or it would be the front seat of his car. We stopped and I quickly crawled
out beside the car,
yanked my pants down and started. In the deep snow I didn't have good footing, so my
butt rest against
the front fender to steady myself." </font></p>
<p>
<font face="Arial" size="4">"My companion stood at the rear of the car watching for
traffic and indeed was a
real gentleman and refrained from peeking. All I could think about was the relief I
felt despite the rather
embarrassing nature of the situation" </font>
</p>
<p>
<font face="Arial" size="4">"Upon finishing however, I soon became aware of another
sensation. As I bent to
pull up my pants, I discovered my buttocks were firmly glued against the car's
fender. Thoughts of tongues
frozen to pump handles immediately came to mind as I attempted to disengage my
delicate flesh from the icy
metal. It was quickly apparent that I had a brand new problem due to the extreme
cold." </font>
</p>
<p>
<font face="Arial" size="4">"Horrified by plight and yet aware of the humor of the
moment, I answered my
date's concerns about &quot;what is taking so long&quot; with a reply that indeed, I
was freezing my butt off and in
need of some assistance! He came around the car as I tried to cover with my sweater
and then, as I looked
imploringly into his eyes, he burst out laughing. I too got the giggles and when we
finally managed to
compose ourselves, we assessed the dilemma." </font>
</p>
<p>
<font face="Arial" size="4">"Obviously, as hysterical as the situation was, we also
were faced with a real
problem. We both agreed it would need something hot to free my chilly buttock from
the grip of the icy
metal! Thinking about what had gotten into this predicament in the first place, both
quickly realized that
there was only one way to get me free. So, as I looked the other way, my first-time
date proceeded to unzip
his pants and pee my clean butt off the fender. Oh Boy..." </font>
<input type="button" value=" Sound Effect " onclick="playSound()"/></p>
<p><font face="Arial" size="4">As
the audience screamed in laughter, she took the Tonight Show prize hands down.. or
perhaps that should be
"pants down."&nbsp; And you thought your first date was embarrassing. Jay Leno's
comment.. "This
gives a whole new meaning to being pissed off<i><b>!</b></i>"</font></p>
<p><br></p>
</body>
</html>
 
T

Trevor L.

Hi Trevor L.
The answer is NO! , GT because PRW:
http://www.webopedia.com/quick_ref/textmessageabbreviations.asp
Here's my complete html code, I referred my sound to my actual PC location
to test it.

Referring to the local file will work for testing

The answer (to what was the whole story) was just as good and acceptable to
kids if PRW

I have had a look at the code (well, that's how I saw the whole story.)
The function should be:
function playSound(fname)
{
if (!fname)
// fname="G:\My Project\Final\Worst Funny Story\sound001.wav"
fname = "G:\My Project\Final\Worst Funny Story\sound001.wav"
var x = document.getElementById("sound")
x.innerHTML = (!x.innerHTML ) ? '&lt;embed src="' + fname + '" loop=false
autostart=true hidden&gt;' : ''
}

The tag in the body should be
<span id="sound"></span>
Does it required 3 times for sound location?

Do you want to play it from 3 buttons?
Otherwise I can't see why you would to add the code 3 times.
And still no sound effect heard.

The problem is the the function - in the parameter in getElementById
Can I use Rich Text here to point emphasis so we can undertand well?

If you send a post in HTML rather than plain text I should be able to read
it
Can you also insert background music then when I press the
Sound Effect button the music will stop playing and sound effect come out.

It is possible. Once we get the sound working, we can try this.
The statement that ends in : '' would be altered to : 'background.wav' but
it may not be that straightforward as orginally this is null, so we need
First click: Play Sound Effect
Second Click: Play background
Third Click: ???
So there will have to be some extra tests in the code, not just swapping
between null and the Sound Effect
Can you also make the button follow scaleable text?

I don't understand "follow scaleable text" You may be able to format the
text on the button - not sure.
BTW, hope you uses F3 then input my name to find my thread faster.

I use Outlook Express newsreader, If I keep up with it every day, then
answers to previous threads which I haven't read and deleted will appear
under the thread, and it is easy to pick out
I really appreciate your kind helps. ---Rino

I trust I answered what I can for now

GBTM when you get the Sound Effect working and I can look at changing it to
the background.
GBTM == Get Back To Me; not on the list of abbreviations
 
T

Trevor L.

Rino,
Responses in-line in Arial 12

Hello Trevor L.,

I considered you my mentor and I'm your good student. If I got this right - both of us will be satisfied and ultimately I can help others or they can follow my threads here.

Interesting to think I am mentoring someone in writing for the web. I am still only 18 months into doing this, but I was a professional programmer in a previous life (with the Australian Bureau of Statistics.) Still, I am happy to do so.

I'm happy you allow me in html language text --- hope you do the same thing. Now I can point to the very spot in question. Example: I'll answer all your questions in your own message text body BUT I used BLUE color texts. And all RED color text are in question or to be check by you -- my mentor. With this agreed method everybody who is following this thread will says TYVM. Please read my answer below . . .

I hope I can do the same thing. I am editing in Wordpad and will insert into OE as HTML and see if that works. (It didn't quite work. I had to reset my replies to Arial 12 in OE).


Hi Trevor L.
The answer is NO! , GT because PRW:
http://www.webopedia.com/quick_ref/textmessageabbreviations.asp
Here's my complete html code, I referred my sound to my actual PC location to test it.

Referring to the local file will work for testing TYVM

The answer (to what was the whole story) was just as good and acceptable to kids if PRW GBU

I have had a look at the code (well, that's how I saw the whole story.)
The function should be: (are all my insertion correct here?)
function playSound(fname)
{
if (!fname)
// fname="G:\My Project\Final\Worst Funny Story\sound001.wav"
fname = "G:\My Project\Final\Worst Funny Story\sound001.wav"
var x = document.getElementById("sound")
x.innerHTML = (!x.innerHTML ) ? >embed src="' + fname + '" loop=false
autostart=true hidden>' : '' ( I changed &gt; to > and the last is 2 '___' and not " only ) correct?
}

The last statement should be (all on one line):
x.innerHTML = (!x.innerHTML) ? '<embed src="' + fname + '" loop=false autostart=true hidden>' : ''

The characters after src are double quote(") then single quote(').
The characters after fname + are single quote(') then double quote(").
The characters after : are two single quotes(''), which indicates a null.

I think you got the opening < incorrect and the quotes a bit astray.

The tag in the body should be
<span id="sound"></span> (This line not given before -- I did inserted this new line BUT still no sound heard)

Maybe it is the error in the function causing the sound to not be heard.

<input type="button" value=" Sound Effect " onclick="playSound()"/> (This 2nd line found below)

<p>
<font face="Arial" size="4">"Obviously, as hysterical as the situation was, we also were faced with a real problem. We both agreed it would need something hot to free my chilly buttock from the grip of the icy metal! Thinking about what had gotten into this predicament in the first place, both quickly realized that there was only one way to get me free. So, as I looked the other way, my first-time date proceeded to unzip his pants and pee my clean butt off the fender. Oh Boy..." </font>
<input type="button" value="Play Sound Effect Now" onclick="playSound()"/></p>

Does it required 3 times for sound location?

Do you want to play it from 3 buttons? NO,
Otherwise I can't see wshy you would to add the code 3 times. I thought every "____" must be referred to. THNQ Sir, 4 pointing that out.

I am not sure what every "____" means. Is this every Id or what? It is true that you can only use a specific ID once on a page - after all, it is an identifier. But that may not be what you mean. In any case, I think you are right not to worry.
And still no sound effect heard.

The problem is the the function - in the parameter in getElementById PTMM (Please tell me more)

The parameter to getElementByID must be an Id present somwhere it the HTML code said:
Can I use Rich Text here to point emphasis so we can understand well?

If you send a post in HTML rather than plain text I should be able to read it TYVM
Can you also insert background music then when I press the Sound Effect button
the music will stop playing and sound effect come out.

It is possible. Once we get the sound working, we can try this.
The statement that ends in : '' would be altered to : 'background.wav' but
it may not be that straightforward as originally this is null, so we need
First click: Play Sound Effect
Second Click: Play background NO, my background sound is always playing until reader's reach to the Button that ask Play Sound Effect Sound.
Third Click: ??? No need
So there will have to be some extra tests in the code, not just swapping between null and the Sound Effect No need

Unfortunately, the function PlaySound will toggle between sound001.wav and null when the button is clicked. So we will need to make sure that each button click does as below:
No Click: Background
Firts Click: sound001.wav
Second Click; Background
Third and subsequent Clicks: No change ???
Can you also make the button follow scaleable text?

I don't understand "follow scaleable text" You may be able to format the
text on the button - not sure. No need, I double checked it and it did followed or stayed in right position as my text getting bigger or smaller in size --- by using Ctrl+Scroll Wheel scroll toward you.
BTW, hope you uses F3 then input my name to find my thread faster.

I use Outlook Express (OE) newsreader, If I keep up with it every day, then answers to previous threads which I haven't read and deleted will appear under the thread, and it is easy to pick out. Yes, I also use OE but it is more faster if you uses F3 key + rino > hit Enter key. F4 to repeat if I've several posts scattered around. F5 to refresh or get newly posted message. You can also uses your own name (or other names) to follow your (or theirs) answered threads. Please uses F3 and keyboard rather than to uses mouse device and scrolling search --- just try it and you'll loved it. Hey, I loved to help others too and answered several n00b (newbie) that were posted in the past years.


Well, I didn't know that. I will have to paste this reply into my "Tips and Tricks" folder.
But after I have deleted read messages, this action won't retrieve them again.
I really appreciate your kind helps. ---Rino

I trust I answered what I can for now TYVM

GBTM when you get the Sound Effect working and I can look at changing it to the background.
GBTM == Get Back To Me; not on the list of abbreviations. Yes, UKTR and YKWYCD -- If you know of a text message abbreviation that is not included in our list, let us know. You'll be famous and I always remember you. LOL

Well, I like IGBTY (I'll get back to you), which is where I adapted GBTM (from I suppose it should be PGBTM (Please get back to me)

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

My new replay:

I did changed and corrected everything and followed your latest advice as I mentioned above --- still no sound heard. I also encountered 2 error messages: #1, when I clicked for Preview mode; its says: Line 16, Char 74, Error=Undermined string constant, Code=0; and #2, when I hit the Button to play sound, Line 76, Char=1, Error=Object expected, Code=0.

I think making the changes above might help a bit. Of course. I should take the copyof the entire code and try it in my browser (IE6). That way I will know whether it works

Regards & TYVM,

Rino

P.S.// BTW, have you set your Text Characters Wrapping at the highest 132 in Plain Text sending? I'm only receiving shorter text characters sentences and not occupying the whole length --- horizontally ;o)

I'll look into that.

Meantime, I'll try to send this in HTML.I have set News Sending Format to HTML in the OE options, so here's hoping it works!

Our next reply will be much shorter ;o)

Well, that was all good fun

HTHFY (Hope to hear from you)
 
T

Trevor L.

I am not sure what font to reply in. I'll use Arial 12

Hi Trevor L.,

Thanks! We found the error. I'm very ;o) because my sound effect is working now!

<script type="text/javascript">
function playSound(fname)
{
if(!fname) input only file name and not actual location
//fname="sound001.wav"
fname="sound001.wav"
var x = document.getElementById ("sound")
x.innerHTML = (!x.innerHTML) ? '<embed src="' + fname + '" loop=false autostart=true hidden>' : ''
}
</script>
<body>
<p>
<span id="sound"></span>

<input type="button" value="Play Sound Effect" onclick="playSound()"/></p></body>

The filename should be relative. This could be difficult when navigating from your web folder to another on the same drove. It is much better to have the file on the same folder.

My final attempt:
Unfortunately, the function PlaySound will toggle between sound001.wav and null when the button is clicked. So we will need to make sure that each button click does as below:
No Click: Initial play Background Sound #1
__Second Click: sound001.wav (Sound Effect)__if not possible to add more music then only 2 will do but toggle the 2

Third Clicks: Background Sound #2

Fourth Click: sound001.wav (Sound Effect)

Subsequent Clicks: Repeat

My thoughts are to use the PlaySound function to toggle between backgrounds and sound effect. To do this, delete the code playing the background sound and rely on the PlaySound function to play whatever is given to it.

I have assumed in the code below that "repeat' above means repeat from sound001.wav (i.e. that background #1 is not required again - if not true, then I need to rewrite this a bit)

var pS_no = 0
function playSound()
{
var fname
if (pS_no == 0)
fname = 'background1.wav'
else
if (pS_no ==1)
fname = 'sound001.wav'
else
fname = 'background2.wav'

pS_no = (pS_no % 2) + 1
document.getElementById("sound").innerHTML
= '<embed src="' + fname + '" loop=false autostart=true hidden>'
}

The <body> tag would read
<body onload="playSound()">

Then in the <body>, use:
<span id="sound"></span>
<input type="button" value="Play Sound Effect" onclick="playSound()"/></p></body>

I have yet to test this, but the idea is to use a global variable pS_no, set initially to 0.
(Note that it must be declared outside the function.)
Then we use this to determine which sound to play

The function playSound() is called onload.
pS_no is zero so fname becomes 'background1.wav'.
pS_no is then reset to the modulus of pS_no, base 2 and 1 is added to it (i.e. the modulus of 0 is 0; add 1 and it becomes 1)

When playSound() is executed from by onclick="playSound()":
pS_no is 1 (as previously set) so sound001.wav is played.
pS_no is then reset to the modulus of pS_no, base 2 and 1 is added to it (i.e. the modulus of 1 is 1; add 1 to this and it becomes 2)

When playSound() is executed again from by onclick="playSound()":
pS_no is 2 (as previously set) so backgound2.wav is played.
pS_no is then reset to the modulus of pS_no, base 2 and 1 is added to it (i.e. the modulus is 0; add 1 and it becomes 1)

When playSound() is executed again from by onlick="playSound()", the process repeats

So
Load: Background Music 1
First Click : Sound Effect
Second Click: Background Music 2

Subsequent Clicks: Repeat actions for First and Second Click

Hope this works. If not, then I wll try it. (I'll need to find 3 sound files - perhaps I can sample some mp3s I have)

Regards,
Rino
 
T

Trevor L.

Hi Rino,
Replies in Arial 12 point

Hi Trevor L.,

TYVM, My reply are in Times New Roman text. I did tried your latest code (shown below) and referred the 2 Background sounds files. Everything came out alright except Background Sound #1 is not in the repeat process. I also rewrote my special request below --- no more 4th clicks BUT subsequents Repeat clicks to make it not too complex but achieve the same purposes.

I'll be your testing partner's and will report back all findings. This is fun and I'm learning from you.

Well, I'm having fun too. It's always great to work through a problem until you find the answer you want.


I am not sure what font to reply in. I'll use Arial 12

The filename should be relative. This could be difficult when navigating from your web folder to another on the same drove. It is much better to have the file on the same folder. Yes, I've put all files in the same folder. Luckilly I found it out --- the JavaScript wants ONLY the file name.

My final attempt:
Unfortunately, the function PlaySound will toggle between sound001.wav and null when the button is clicked. So we will need to make sure that each button click does as below:

No Click: Initial play Background Sound #1
Second Click: sound001.wav (Sound Effect)
Third Clicks: Background Sound #2
Subsequent Clicks: Repeat all sequents starting from No Click and downward.

My thoughts are to use the PlaySound function to toggle between backgrounds and sound effect. To do this, delete the code playing the background sound and rely on the PlaySound function to play whatever is given to it.

I have assumed in the code below that "repeat' above means repeat from sound001.wav (i.e. that background #1 is not required again - if not true, then I need to rewrite this a bit)
(yes, it's not true BUT repeat from Background Sound #1 and it is required). THX

var pS_no = 0
function playSound()
{
var fname
if (pS_no == 0)
fname = 'background1.wav'
else
if (pS_no ==1)
fname = 'sound001.wav'
else
fname = 'background2.wav'

pS_no = (pS_no % 2) + 1
document.getElementById("sound").innerHTML
= '<embed src="' + fname + '" loop=false autostart=true hidden>'
}

The <body> tag would read
<body onload="playSound()">

Then in the <body>, use:
<span id="sound"></span>
<input type="button" value="Play Sound Effect" onclick="playSound()"/></p></body>

I have yet to test this, but the idea is to use a global variable pS_no, set initially to 0.
(Note that it must be declared outside the function.)
Then we use this to determine which sound to play

The function playSound() is called onload.
pS_no is zero so fname becomes 'background1.wav'.
pS_no is then reset to the modulus of pS_no, base 2 and 1 is added to it (i.e. the modulus of 0 is 0; add 1 and it becomes 1)

When playSound() is executed from by onclick="playSound()":
pS_no is 1 (as previously set) so sound001.wav is played.
pS_no is then reset to the modulus of pS_no, base 2 and 1 is added to it (i.e. the modulus of 1 is 1; add 1 to this and it becomes 2)

When playSound() is executed again from by onclick="playSound()":
pS_no is 2 (as previously set) so backgound2.wav is played.
pS_no is then reset to the modulus of pS_no, base 2 and 1 is added to it (i.e. the modulus is 0; add 1 and it becomes 1)

When playSound() is executed again from by onlick="playSound()", the process repeats

So . . .
L o a d : Background Music 1
First Click : Sound Effect
Second Click: Background Music 2

T h i r d Click: Background Music 1 (this is actually a 'Repeat' click, subsequent clicks follow Sound Effect, Background Music 2, etc., keep Repeating when being click.

I think I've got it

As you are doing the testing, I'll just post the code that I think will work.

1. Leave the HTML alone.
It should have:
<body onload ="playSound()">
<input type="button" value=" whatever " onclick="playSound()" />

2. Alter the function.
I have changed the code so it looks neater, using a special style of "if then else" statement

var pS_no = 0
function playSound()
{
var fname = (pS_no == 0) ? 'background1.wav'
: (pS_no == 1) ? 'sound001.wav'
: (pS_no == 2) ? 'background2.wav'
pS_no = (pS_no % 2) + 1
document.getElementById("sound").innerHTML
= '<embed src="' + fname + '" loop=false autostart=true hidden>'
}

Subsequent Clicks: Repeat actions for First and Second Click (correction: From Load to Third Click ---please refer above)

I think you mean "from Load to Second Click"
This should cycle through 3 options
0 NoClick: Background Sound #1
1 First Click: Sound Effect
2 Second Click: Background Sound #2

And repeat as follows
3rd, 6th, 9th, etc. : As for Load (No Click)
4th, 7th, 10th, etc.: As for First Click
5th, 8th, 11th, etc.: As for Second Click

If it doesn't work, then I have got something wrong.

Hope this works. If not, then I wll try it. (I'll need to find 3 sound files - perhaps I can sample some mp3s I have) (it's working beautifully! but one . . .)

Regards, HAND, (Have a nice day)
Trevor L. --- Rino

Would you please post the url of the final web page so I can view the masterpiece.

Or is it an intranet site ?
If so, you can find my web address by visiting my website and email it to me there

As one of the MVPs here signs off:
Keep having fun
 
T

Trevor L.

Replies again in Arial 12

Hi Trevor L.,

Not good this time --- zero audio or music, with 3 error messages:

<script type="text/javascript">
var pS_no = 0
function playSound()
{
var fname = (pS_no == 0) ? "el_condora_passa.wma"
:(pS_no == 1) ? "sound001.wav"
:(pS_no == 2) ? "AMENO..wav"
pS_no = (pS_no % 2) + 1
document.getElementById("sound").innerHTML -------(1st Error message: Line 16, expected ":" )
= '<embed src="' + fname + '" loop=false autostart=true hidden>' (Error message appears on Preview mode)
}
</script></head>

I hate the error expected ":" - I can never solve it (grumpy smiley should appear here)

<! -- in <body> I use this code --> 2nd error says Line 75, Object Expected (OE)

However this message gives me a bit of hope. It means that the function called does not "compile", i.e. it is not valid

My only thought at this stage and it is clutching at straws a bit is:
Did you cut and paste your code into the text above?
If so, "AMENO..wav" is invalid as a filename.
Should it be "AMENO.wav"

The fact that the error appears at the point where the innerHTML is being set seems to support this idea. I am afraid I can't see anything else wrong. (But I often write what I think is error-free code and it fails dismally - see my post to dancer today!!)

<body onload ="playSound()"></body> 3rd error says Line 76, OE, upon clicking the button
<input type="button" value="Play Sound" onclick="playSound()"/></p>


If it doesn't work, then I have got something wrong.

Hope this works. If not, then I wll try it. (I'll need to find 3 sound files - perhaps I can sample

some mp3s I have)


Would you please post the url of the final web page so I can view the masterpiece. YES, I will

Or is it an intranet site ?
If so, you can find my web address by visiting my website and email it to me there OK

As one of the MVPs here signs off:
Keep having fun

--
Cheers, HAND, (Have a nice day)
Trevor L. --- Rino
Website: http://tandcl.homemail.com.au

Ah well, let's keep trying . After all it worked before with just a problem in which files were being played, so the solution can't be far off.
 

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

Top