PDA

View Full Version : ahhh!!!!! help javascript is attacking me!!!


killa
02-09-2003, 12:39 AM
:confused: it is not really attacking me but it is annoying me.
1.can you put a if command with only a function? like this:
if(sound())
{
hello()
}


2.how do you do music?

3.can you make it like when theres a box poping up in random places and when you click it it will make a sound and contine?



thx for looking! :thumbsup:

joeframbach
02-09-2003, 04:25 PM
1)yes.
2)i'm too lazy right now
3)tweak my target practice (http://www.geocities.com/joeframbach/target.html) script.

killa
02-09-2003, 04:47 PM
ok thx for that help but...
1. can you put a if comand not in a function like :
function stuff()
//function stuff starts
{
blah blah blah
}//function stuff ends

if(stuff())
//if starts
{
blah blah blah!
}
//if ends

2. wat about your target practice thing?

boywonder
02-10-2003, 12:40 AM
Hi killa,
To answer your question, you can use a function inside a condition like that, but the function must return a value. otherwise the condition will be false every time.

To get the most from these forums, it is better to run some tests on your own to see if you can do what you want, and if it doesn't work then post the code here and ask your questions.

good luck

killa
02-10-2003, 02:36 AM
ok sorry but i dont think you understud my question. i made a function and i want to put a if command after were the function ends. i did try it out but its not working and i cant put the code up cuz its toooooo big!

joeframbach
02-10-2003, 01:29 PM
oh!!! i understand...

function stuff()
{
//function stuff here
return true;
}

if(stuff()==true)
{
//if stuff here
}



furthermore, i'd put the if in a function to do onLoad. you dont want JS to access elements that arent loaded yet.

killa
02-10-2003, 08:36 PM
i am sorry but i tryed it and it did not work. wat i am trying to do is that when you press the botton "S" a picture will move on the screen and at the same time it will play a little sound like a short beep.

joeframbach
02-11-2003, 01:25 AM
you should've said so! this should work, too!

function press()
{
if(String.fromCharCode(event.keyCode)=='S')
{
picture.style.left=500
soundThing.innerHTML="<EMBED src='sound.mid' autostart=true visibility='hidden' loop='false'>"
}
}

<body onKeyPress="press()">
<div id=picture></div><div id=soundThing></div>

killa
02-11-2003, 09:00 PM
ok i am sorry but it does not work (i probeble put it it wrong but it does not work)
i put it like this:

<html>

<head>


</head>

<body>
<SCRIPT LANGUAGE="Javascript"><!-- start
function press()
{
if(String.fromCharCode(event.keyCode)=='S')
{
picture.style.left=500
soundThing.innerHTML="<EMBED src='gunshot.wav' autostart=true visibility='hidden' loop='false'>"
}
}
end -- !>

</script>

<body onKeyPress="press()">
<div id=picture></div><div id=soundThing></div>
</body>

</html>

Code_gate
02-11-2003, 09:08 PM
Anything above <body onKeyPress="press()"> should be contained within the <head></head> tags.

killa
02-11-2003, 09:18 PM
um....ok still not working:


<html>
<head>

<SCRIPT LANGUAGE="Javascript">
<!-- start
function press()
{
if(String.fromCharCode(event.keyCode)=='S')
{
picture.style.left=500
soundThing.innerHTML="<EMBED src='gunshot.wav' autostart=true visibility='hidden' loop='false'>"
}
}
end -- !>
</script>

</head>
<body>

<body onKeyPress="press()">
<div id=picture></div><div id=soundThing></div>
</body>
</html>

joeframbach
02-13-2003, 04:17 PM
<html><head>
<SCRIPT LANGUAGE="Javascript"><!--
function press(){
if(String.fromCharCode(event.keyCode).toUpperCase()=='S')
alert('S')
}
--></SCRIPT>
</head>
<body onKeyPress="press()">
<div id="picture"></div><div id="soundThing"></div>
</body></html>

maybe the divs were faulty