all groups > flash actionscript > december 2005 >
You're in the

flash actionscript

group:

Calculating x and y coordinates of a point over a distance


Calculating x and y coordinates of a point over a distance Mike Von Mau
12/25/2005 9:58:09 AM
flash actionscript:
How can I find the coordinates of a clip I want to add to the root stage if i
have for example the following information

-the coordinates (x and y) of 2 clips
-the distance between 2 clips
-the angle between 2 clips

no say i want to add 3 clips between the 2 clips (evenly spaced). How can I
calculate the x and y of the 3 clips

please help it is taking me an day already :(
And I used to be so good in Math ( 10 years ago )
Re: Calculating x and y coordinates of a clip between other clips tralfaz
12/25/2005 11:09:13 AM

[quoted text, click to view]

There are a couple of problems with your formula kglad.
Your code with a couple of small changes..

for(var k=1;k<=3;k++)
{
_root["mc"+k]._x = _root.mcA._x + (((mcB._x - mcA._x) / 4) * k);
_root["mc"+k]._y = _root.mcA._y + (((mcB._y - mcA._y) / 4) * k);
}

Note.. Create objects with center registration so you won't need to
divide the widths and heights.
tralfaz



Re: Calculating x and y coordinates of a clip between other clips kglad
12/25/2005 3:45:21 PM
do the 3 movieclips have the same _width and _height? if not, what do you mean
by evenly spaced? if yes, you can use and by evenly spaced you mean to
position their centers evenly between the two anchor movieclips, you can use:

for(var i=1;i<=3;i++){
_root["mc"+i]._x=i*(mcB._x-mcA._x-mcA._width)/3-_root["mc"+i]._width/2;
_root["mc"+i]._y=i*(mcB._x-mcA._y-mcA._height)/3-_root["mc"+i]._height/2;
}

where mc1,mc2,mc3 are your movieclips to be positioned and mcA is your left
most reference movieclip and mcB is your right most
AddThis Social Bookmark Button