SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Threaded View

  1. #1
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Last edited by spartan; Jul 11, 2002 at 00:33.
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne


Bookmarks

Posting Permissions

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