SitePoint Sponsor

Thread: assigning a value to a function result...??!!

1. assigning a value to a function result...??!!

ok I have 8 divs, I slide 4 of them in from the left side of the screen and the other 4 from the right side.

at the moment I have the code for each one... well... for the lack of a better word... hard-coded in one function. meaning I have code like this.

Code:
```Function slide(){
//=============================BOX1=======================================\\
if (begin)
{
//slide horizontily
if (slideX < CircleEdge_left)
{
slideX+=8;
box1.style.left = slideX;

}
else{
begin=false

}
}
else
//slide arch
{
if (angle1<360)
{
// get the new offset
delta_x = radius*Math.cos(angle1*Math.PI/180);
delta_y = radius*Math.sin(angle1*Math.PI/180);

//compensate for starting position
actual_x = midpoint_x + delta_x;
actual_y = midpoint_y + delta_y;

//implement position change
box1.style.left = actual_x + "px";
box1.style.top =  actual_y + "px";

//increase the angle
angle1+= speed;

}
}

//=============================BOX2=======================================\\
if (begin2)
{
//slide horizontily
if (slideX2 < CircleEdge_left)
{
slideX2+=8;
box2.style.left = slideX2;

}
else{
begin2=false

}
}
else
//slide arch
{
if (angle1<360)
{
// get the new offset
delta_x2 = radius*Math.cos(angle2*Math.PI/180);
delta_y2 = radius*Math.sin(angle2*Math.PI/180);

//compensate for starting position
actual_x2 = midpoint_x + delta_x2;
actual_y2 = midpoint_y + delta_y2;

//implement position change
box2.style.left = actual_x2 + "px";
box2.style.top =  actual_y2 + "px";

//increase the angle
angle2+= speed;

}

}```

and so on... and so on.... for each of the boxes.

So then I tried to clean it up a bit. I thought I would have a variable holding the number of boxes I wanted, then in my function I would simply have one piece of code inside a loop.
something like this...
Code:
```for (count=1 to number of boxes)
eval("box"+count+".style.left") = newposition
count++
next```
but I encountered this error: cannot assign a value to a funtion result....

So, my question is this.... how can I get around this. is there a way? or do I really need to "hardcode" all the code for each of the boxes?

hope someone can help me

cheers

2. I think the two questions override each other.
If you adopt a different technique - the error may well
disappear - hence I'll answer one.

Not sure why i've never shown this before .. but...

A while ago i wanted to see how easy it would be to create objects and control them with generic functions.

http://www.kodetortoise.com/develop/jesoop.html

See if that points anything out for you - you'd only need the simplest of the functions.

Flawless

3. interesting...
but what am I looking for? the use of arays or the use of getelementbyid()??

i'm still not exactly shure how I'm gonna get around the error I'm getting...

4. OK, got it working perfectly.

Thanx for the link.

5. The link shows how several objects can move through one single function.

Flawless

6. cool
thanx

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•