...

View Full Version : help with animation function



snakedevil1
08-04-2002, 08:20 PM
Everytime i run this code through, i get a line 66 character 1 object expected error. i have NO idea what it is. Please help!

var currentstate=1;

function GoTo(id)
{
var howfar;
var way;
if (id > currentstate)
{ howfar=id-currentstate; way="right"; } else { howfar=currenstate-id; way="left"; }
var distance;
var result;
switch (way) {
case "right"
distance=howfar*75;
result=document.getElementById(selector).style.left+distance;
break;
case "left"
distance=howfar*75;
result=document.getElementById(selector).style.left-distance;
break;
}

if(document.getElementById(selector).style.left=result)
{clearTimeout(animation);animation=0;} else {
function="GoTo(" + id + ");";
animation=setTimeout(function,50);}
}

snakedevil1
08-04-2002, 09:52 PM
fixed it up a little, but still get the same error:
var currentstate=1;

function GoTo(id)
{
var howfar;
var way;
if (id > currentstate)
{ howfar=id-currentstate; way="right"; } else { howfar=currenstate-id; way="left"; }
var distance;
var result;
switch (way) {
case "right"
distance=howfar*75;
result=document.getElementById(selector).style.left+distance;
break;
case "left"
distance=howfar*75;
result=document.getElementById(selector).style.left-distance;
break;
}

if(document.getElementById(selector).style.left=result)
{clearTimeout(animation);animation=0;} else {
animation=setTimeout(GoTo,50,id);}
}

snakedevil1
08-04-2002, 10:16 PM
thanx for the help, but i get the same error, this time when i click on it.
by the way, my website is at vip3r.port5.com

Graeme Hackston
08-04-2002, 10:18 PM
I deleted my reply hoping not to confuse you. I was wrong, all the brackets are there.

snakedevil1
08-04-2002, 10:30 PM
thanx for ur help. now, after a little bit of editing, i get a line 36 character 1 error. any help would be appreciated!

var currentstate=1;

function GoTo(id) {
var howfar;
var way;
if (id > currentstate) {
howfar=id-currentstate; way="right";
} else {
howfar=currenstate-id; way="left";
}
var distance;
var result;
switch (way) {
case "right":
distance=howfar*75;
result=document.getElementById(selector).style.left+distance;
break;
case "left":
distance=howfar*75;
result=document.getElementById(selector).style.left-distance;
break;
}
if(document.getElementById(selector).style.left=result) {
clearTimeout(animation);animation=0;
} else {
animation=setTimeout(GoTo,50,id);}
}

Graeme Hackston
08-04-2002, 10:37 PM
what is "selector"? If it's an element id it should be like this:

('selector')

snakedevil1
08-04-2002, 10:58 PM
ok,thanx.
now that i fixed it, i got a line 43 character 1 error. :)
var currentstate=1;

function GoTo(id) {
var howfar;
var way;
if (id > currentstate) {
howfar=id-currentstate; way="right";
} else {
howfar=currenstate-id; way="left";
}
var distance;
var result;
switch (way) {
case "right":
distance=howfar*75;
result=document.getElementById('selector').style.left+distance;
break;
case "left":
distance=howfar*75;
result=document.getElementById('selector').style.left-distance;
break;
}
if(document.getElementById('selector').style.left=result) {
clearTimeout(animation);animation=0;
} else {
animation=setTimeout(GoTo,50,id);}
}

Graeme Hackston
08-04-2002, 11:06 PM
Just guessing but try this

animation=setTimeout(GoTo(),50);
}

Graeme Hackston
08-04-2002, 11:09 PM
Actually I think it should be like this

animation=setTimeout('GoTo()',50);
}

snakedevil1
08-04-2002, 11:17 PM
i need to pass id to GoTo though, otherwise it wouldn't know where to go, right? thanx for ur help!

Graeme Hackston
08-04-2002, 11:22 PM
Maybe this?

animation=setTimeout('GoTo(id)',50);
}

snakedevil1
08-04-2002, 11:28 PM
i think what u mean is this:
setTimout("'GoTo(' + id + ');'");
and nope, still doesn't work :)

snakedevil1
08-04-2002, 11:39 PM
ok, i rewrote it so it makes some more sense now. Now it looks like this:

var wheretogo;
var whereis;
function GoTo(id)
{
whereis=document.all.selector.offsetLeft;
var whereisbyid;
switch(whereis)
{

case: 75
whereisbyid=1;

case: 150
whereisbyid=2;

case: 225
whereisbyid=3;

case: 300
whereisbyid=4;
}

if(whereisbyid>id)
{way="left"}

wheretogo=id*75;
var animation=setInterval("GoToPlace();",50);
}

function GoToPlace()
{

if(wheretogo != whereis)
{ whereis=whereis+1; } else {clearInterval(animation)}

}

snakedevil1
08-04-2002, 11:41 PM
i still get a line 30 character 8 object expected error

Graeme Hackston
08-04-2002, 11:41 PM
Still just guessing.

Where does "animation" come in? Is it part of another script?

snakedevil1
08-04-2002, 11:43 PM
animation is the variable set with the setinterval, clearinterval uses that to stop it

Graeme Hackston
08-04-2002, 11:51 PM
Sorry I missed that.

snakedevil1
08-04-2002, 11:52 PM
no problem



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum