Hi all, there was a question how to prevent images coming in too fast, for example if images are loaded on webcam activity.
The principle is to use a timer to get the delay.
The timer starts and a blocker is put in between the events coming in and the loading.
After the timer has expired, the blocker is removed.
You can use a Number as a blocker, using 0 and 1 for example but here we use a Boolean.
A boolean can only be true of false (0 or 1).
var stoppingEvents:Boolean = false;
we use a delay timer, when it starts events will not cause reactions:
var delayTimer:Timer = new Timer(1000); //timer delay is 1000 milliseconds
delayTimer.addEventListener("timer", goOnListening);
This is how we stop events:
function keyDownHandler ( event:KeyboardEvent ): void
{
if ( stoppingEvents == false )
{
if (String.fromCharCode( event.charCode) == "1") //the active key is "1"
{
readSound("1.mp3");
stoppingEvents = true; //blocking the next 1000 milliseconds any sounds
delayTimer.start();//count down to give the listener free
}
}
}
we have started the timer here, when it is done:
function goOnListening (event:TimerEvent ) {
stoppingEvents = false;
delayTimer.stop(); //stopping th timer
}
it removes the blocker....
here is the source code:
http://www.contrechoc.com/flash/blockEvent.zip
of course this example can be used for blocking mouse events, webcam events, microphone events just as easy....
Aucun commentaire:
Enregistrer un commentaire