Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / January 2006



Tip: Looking for answers? Try searching our database.

ignore document.onkeyup events for set a period?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
paul.sherwood@gmail.com - 27 Jan 2006 16:26 GMT
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
Evertjan. - 27 Jan 2006 16:57 GMT
wrote on 27 jan 2006 in comp.lang.javascript:

> Hi
>
[quoted text clipped - 22 lines]
> 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.

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

paul.sherwood@gmail.com - 27 Jan 2006 17:04 GMT
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.
paul.sherwood@gmail.com - 27 Jan 2006 17:31 GMT
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.
paul.sherwood@gmail.com - 27 Jan 2006 17:37 GMT
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.
Evertjan. - 27 Jan 2006 18:11 GMT
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

}

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

paul.sherwood@gmail.com - 31 Jan 2006 10:56 GMT
Thanks Evertjan, the above works splendidly. Suddenly its all become
clear.

Paul
Evertjan. - 31 Jan 2006 11:13 GMT
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/>

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Randy Webb - 27 Jan 2006 17:04 GMT
paul.sherwood@gmail.com said the following on 1/27/2006 11:26 AM:
> Hi
>
[quoted text clipped - 7 lines]
> <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;
}

Signature

Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.