By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

ignore document.onkeyup events for set a period?

P: n/a
Hi

Ive made a game for babies that simply displays one of an array of
pictures of animals along with there sound each time the keyboard is
'bashed'.

at the moment i dynamically load pictures using

<img id="image" src="somepic.gif" alt="" border=0px/>
<script type="text/javascript">
document.onkeyup=changeImageSrc;
</script>

and

function changeImageSrc(){
..
..
document.getElementById('image').src = nextImage; //nextImage is
already loaded from the image array
}

This works great for adults. However babies dont tend to wait for the
image and sound to have played before bashing again, so lots of keyup
events come along and the page ends up being a blur of images and
sounds. How might i best remedy this issue?

thanks in advance

Paul

Jan 27 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
wrote on 27 jan 2006 in comp.lang.javascript:
Hi

Ive made a game for babies that simply displays one of an array of
pictures of animals along with there sound each time the keyboard is
'bashed'.

at the moment i dynamically load pictures using

<img id="image" src="somepic.gif" alt="" border=0px/>
<script type="text/javascript">
document.onkeyup=changeImageSrc;
</script>

and

function changeImageSrc(){
.
.
document.getElementById('image').src = nextImage; //nextImage is
already loaded from the image array
}

This works great for adults. However babies dont tend to wait for the
image and sound to have played before bashing again, so lots of keyup
events come along and the page ends up being a blur of images and
sounds. How might i best remedy this issue?


Ideas:

1 Prevent the changeImageSrc() execution for a fixt time with setTimeout()

2 Use setTimeut() to wait till the babies are older.

3 Preload the images.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 27 '06 #2

P: n/a
pa***********@gmail.com said the following on 1/27/2006 11:26 AM:
Hi

Ive made a game for babies that simply displays one of an array of
pictures of animals along with there sound each time the keyboard is
'bashed'.

at the moment i dynamically load pictures using

<img id="image" src="somepic.gif" alt="" border=0px/>
<script type="text/javascript">
document.onkeyup=changeImageSrc;
var runTheFunction = true;
</script>
and
function changeImageSrc(){
if (runTheFunction){
runTheFunction = false;
..
document.getElementById('image').src = nextImage; //nextImage is
already loaded from the image array


runTheFunction = true;
}

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 27 '06 #3

P: n/a
Wait till they're older...chuckle

I have tried the setTimeout() function but unfortunately the browser
'remembers' all onkeyup events even during the wait period, which
causes the images to scroll by slower but still uncontrolled.

Jan 27 '06 #4

P: n/a
Unfortunatley the onkeyup events seem to be stored and executed after
the changeImageSrc function has completed, so multiple bashes still
result in multiple pages flashing past.

Jan 27 '06 #5

P: n/a
An alternative approach would be to some how ignore onkeyup events
until the animal sound has finished playing. I use

<bgsound id="sounds" src="sounds/default.wav"/> **i realise bgsound
only works for IE, but the trouble im having with that is a story for
another day
function changeImageSrc(){
..
..
document.getElementById('sounds').src = nextSound;
}

ive no idea how to do that. bgsound doesnt seem to have a
'stillPlaying' method.

Jan 27 '06 #6

P: n/a
wrote on 27 jan 2006 in comp.lang.javascript:
Wait till they're older...chuckle

I have tried the setTimeout() function but unfortunately the browser
'remembers' all onkeyup events even during the wait period, which
causes the images to scroll by slower but still uncontrolled.


No, no, each keyup is processed, but with an "empty process"
till the next baby bounce is accepted again.

Try:

<body onkeyup='doit()'>

<script ...
var wait = false;

function doit(){

if (wait) return;

wait = true;
setTimeout('wait=false',1000);

// and do whatever you were up to originally

}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 27 '06 #7

P: n/a
Thanks Evertjan, the above works splendidly. Suddenly its all become
clear.

Paul

Jan 31 '06 #8

P: n/a
wrote on 31 jan 2006 in comp.lang.javascript:
Thanks Evertjan, the above works splendidly. Suddenly its all become
clear.


There is nothing "above". ;-)

==========================

Please, for the sake of the NG, quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers. <http://www.safalra.com/special/googlegroupsreply/>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 31 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.