Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setTimeout works 1/2 of time

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
I am trying to set up a website that has dHTML animation when the page loads. The page loads, and the functions execute fine. Its in the timeout string that there is a problem. The function that actually moves the layer executes the first time, and then repeats with a timeout, but it quits after that with a javascript error that says something like &quot;error, line 1, char 1, 'object' is undefined, code=0, src=c:\windows\desktop . . .&quot;<br>
<br>
I am using Internet Explorer to do the basic coding, and I havn't even made the &quot;flying&quot; div's id/location a parameter yet, that comes later, after the basic codeing.<br>
<br>
<br>
here is the page:<br>
<br>
<br>
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;&gt;<br>
&lt;HTML&gt;<br>
&lt;HEAD&gt;<br>
&lt;TITLE&gt;dHTML PlANEt, your source for CROSSbROWSER dHTML scripts!!&lt;/TITLE&gt;<br>
&lt;script language=&quot;javascript&quot;&gt;<br>
var timed<br>
function calculateSteps(div,endX,endY,numsteps){<br>
var stepX;<br>
var stepY;<br>
stepX=(endX-parseInt(document.all.PlanetAndMoon.style.left))/numsteps;<br>
stepY=(endY-parseInt(document.all.PlanetAndMoon.style.top))/numsteps;<br>
moveObjWithSteps(div,stepX,stepY,endX,endY);<br>
}<br>
function moveObjWithSteps(div,stepX,stepY,endX,endY){<br>
if((document.all.PlanetAndMoon.style.top!=endY)&&(document.all.PlanetAndMoon.style.left!=endY)){<br>
document.all.PlanetAndMoon.style.top=parseInt(document.all.PlanetAndMoon.style.top)+stepY;<br>
document.all.PlanetAndMoon.style.left=parseInt(document.all.PlanetAndMoon.style.left)+stepX;<br>
setTimeout('moveObjWithSteps('+div+','+stepX+','+stepY+','+endX+','+endY+')',25);<br>
}}<br>
&lt;/script&gt;<br>
&lt;/HEAD&gt;<br>
&lt;body onload=&quot;calculateSteps('PlanetAndMoon',240,120,21);&quot; background=&quot;images/background.gif&quot; id=body&gt;<br>
&lt;div id=PlanetAndMoon style=&quot;position:absolute; top:-10; left:-10; width:300; height:400;&quot;&gt;&lt;a href=&quot;#&quot; onMouseOver=&quot;document.planet.src = 'images/bplanet2.gif'&quot; onMouseOut=&quot;document.planet.src = 'images/planwmoon42.gif'&quot; style=&quot;cursor:sw-resize;&quot;&gt;&lt;img src=&quot;images/planwmoon42.gif&quot; name=planet border='0'&gt;&lt;/a&gt;&lt;/div&gt;<br>
&lt;/BODY&gt;<br>
&lt;/HTML&gt;<br>
<br>
Whatever help you can give is great,<br>
thankyou <p>theEclipse<br><a href=mailto: > </a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>
 
I sympathise&nbsp;&nbsp;-&nbsp;&nbsp;my first attempt at a setTimeout loop took me days.<br><br>You haven't said which line was referred to in the error message&nbsp;&nbsp;-&nbsp;&nbsp;the full error message would be a great help, plus identification of the line it pointed to.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top