i am trying to dynamically load the image of a bullet and then manipulate it using a looping function( with setTimeout() and clearTimeout() methods).
here's the code>>>>
the script loads the image alright but gives an error soon after.
OS: Windows XP Pro and IE 7
lang: JavaScript
error code: code 0
message: 'object' is undefined
line: line 1 char 1
here's the code>>>>
Code:
<html>
<head>
<script type="text/javascript" language="JavaScript">
var timer;
function keyPress( )
{
var bullet=new Image( );
var bowser=document.getElementById("Bowser");
bullet.setAttribute("style","position:absolute;left:0 px;top:0 px;");
bullet.style.top=bowser.style.top;
bullet.style.left=bowser.style.left;
bullet.setAttribute("src","bullet1.jpg");
document.body.appendChild(bullet);
fire(bullet);
}
function fire(bullet)
{
var x=parseInt(bullet.style.left);
var y=x+8;
bullet.style.left=y+" px";
if(x>1024)
{
clearTimeout(timer);
document.body.removeChild(bullet);
}
timer=setTimeout("fire("+bullet+")",50);
}
</script>
</head>
<body onkeypress="javascript:keyPress( )">
<img class="other" id="Bowser" src="D:\Documents and Settings\Administrator\My Documents\My Pictures\Images\mario\Bowser.gif" altText="Bowser" style="position:absolute;top:500 px;left:12 px" />
</body>
</html>
OS: Windows XP Pro and IE 7
lang: JavaScript
error code: code 0
message: 'object' is undefined
line: line 1 char 1
Comment