I'm new to JavaScript and working my way through the Teach yourself JS 1.5 book. All of the scripts in the book work perfectly apart from the listing 20.3 piano example. http://www.jsworkshop.com/js15/list20-3.html
I am using an iMac G5 Mac OSX 10.4.10 Tiger and am getting the error
Expand|Select|Wrap|Line Numbers
- document.embeds[note].play(); is not a function
Expand|Select|Wrap|Line Numbers
- <title>JavaScript Piano</title>
- <script LANGUAGE="JavaScript" type="text/javascript">
- function playnote(note) {
- document.embeds[note].play();
- }
- </script>
- </head>
- <body>
- <embed SRC="C0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="Cs0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="D0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="Ds0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="E0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="F0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="Fs0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="G0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="Gs0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="A0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="As0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="B0.wav" HIDDEN=true AUTOSTART=false>
- <embed SRC="C1.wav" HIDDEN=true AUTOSTART=false>
- <h1>The JavaScript Piano</h1>
- <hr>
- <p>Click on the funny-looking piano keys below to play a melody.</p>
- <hr>
- <a HREF="#" onClick="playnote(0)">
- <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(1)">
- <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(2)">
- <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(3)">
- <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(4)">
- <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(5)">
- <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(6)">
- <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(7)">
- <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(8)">
- <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(9)">
- <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(10)">
- <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(11)">
- <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
- <a HREF="#" onClick="playnote(12)">
- <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
- <hr>
- </body>
- </html>
The example works fine In IE on virtual pc but does not play on Firefox Netscape or Safari on the Mac even from the sites workshop example.
I have heard that different platforms handle script in different ways and i am sure there is a simple solution, but being new to JavaScript i am unable to troubleshoot this any further.
I have asked on other forums and been told its possible mac does not support
this function but given no way to resolve the issue.
I apologize if this is an faq but any help would be much appreciated to get this to work on the mac.
Thanks in advance