PDA

View Full Version : Dynamically placing movie clip at the angle and global position of a mouse click



BiancaB8
September 23rd, 2009, 10:20 PM
Does anyone know the code for finding the global positioning of X & Y co-ordinates of a click of a button which is constantly rotating,
and then secondly the code for when you click on the button it displays a movie clip on top of it -(position of x & y when clicked) at the angle that you clicked it,
so underneath the buttons are still rotating so other people can click them where they are?

to explain the context, I'm trying to design a mock up of a circular interactive table
when someone comes up to it and clicks on one of the buttons that are moving, it reads where the person clicked it and opens up a new box (movie clip) where they clicked it (at the angle) so its not upside down if you are at the top.

I've included my .fla file which shows the four buttons moving and a little diagram
explaining what I'm trying to do.

GrndMasterFlash
September 24th, 2009, 10:56 AM
can't open your file, you must have CS4?

anyways if you set a MouseEvent that reads the XY when you click, vs the XY of the button (which should have a centered registration point) the calculate the angle and off set it by the buttons current rotation you should get the results your looking for.

i know it might sound tricky, but if you need help with any part of that let me know, here is a good one you might need



function calcAngle(p1:Point, p2:Point):Number
{
var diffX = (p1.x)-(p2.x);
var diffY = (p1.y)-(p2.y);
var slope = diffY/diffX;
var angle = (Math.atan2(diffY, diffX)*(180/Math.PI));
if (angle<0)
{
angle += 360;
}
return angle;
}