CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Help! Konami code with sound? (http://www.codingforums.com/showthread.php?t=286036)

Xana513 01-19-2013 01:41 AM

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.

Old Pedant 01-19-2013 03:12 AM

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'


Logic Ali 01-19-2013 04:21 AM

Quote:

Originally Posted by Old Pedant (Post 1307271)

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.


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

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.