setInterval will run over and over by itself, there is no need to call it repeatedly. It is also good to store the reference to a timeout or interval in a variable.
Try this
- Code: Select all
<script type="text/javascript">
var flashObj = document.getElementById("gameJS");
var pl = 0;
var timeout = false;
function showPercent(){
pl++;
if(pl == 10){
clearInterval(timeout);
}
else {
timeout = setTimeout("showPercent()",1000);
}
}</script>
The way your script was working had 10 different intervals running but was only clearing one of them.
This is a timeout so it runs only once.
Cheers,