Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-19-2013, 01:41 AM   PM User | #1
Xana513
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Xana513 is an unknown quantity at this point
Question Help! Konami code with sound?

Hmmm.... i cant seem to get this to work. I was going to use this on my homepage.

When you correctily entered the "Konami Code" your supposed to hear a sound.

Code:
<script type="text/javascript" src="http://konami-js.googlecode.com/svn/trunk/konami.js"></script>
<script type="text/javascript">
    konami = new Konami()
    konami.code = function play() 
 {
     var embed = document.createElement('object');

     embed.setAttribute('src', 'C:\Users\Willium\Music\Area Cleared.wav');
     embed.setAttribute('hidden', true);
     embed.setAttribute('autostart', true);
     embed.setAttribute('enablejavascript', true);

     document.childNodes[0].appendChild(embed);

 }
    konami.play()
</script>
So what I have done is edited the original konami code (code) from just bringing up a textbox saying you have 30 lives to playing a sound. http://www.youtube.com/watch?v=zHOPEjpMv1A

What did i do wrong and why wont it play a sound? Mind you the src for the sound destination is only local because i am testing it first before uploading it to my server.
Xana513 is offline   Reply With Quote
Old 01-19-2013, 03:12 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I don't know if this is the only problem, but...

In JavaScript (and Java/C/C++/C#/other languages) the backslash character is used as an ESCAPE character, giving special meaning to the character it. The \n means "newline" and \t means "tab", etc.

If the following character does not have a special meaning then then the character, alone, is the result. The backslash just disappears.

In order to actually *GET* a backslash, then, you must use a pair of them.

Code:
'C:\Users\Willium\Music\Area Cleared.wav'
became just
'C:UsersWilliumMusicArea Cleared.wav'

so you needed
'C:\\Users\\Willium\\Music\\Area Cleared.wav'
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-19-2013, 04:21 AM   PM User | #3
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Quote:
Originally Posted by Old Pedant View Post

In order to actually *GET* a backslash, then, you must use a pair of them.
For paths it's better always to use forward slashes; the browser knows what to do with them.
Logic Ali is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, konami code, sound

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:28 PM.


Advertisement
Log in to turn off these ads.