This content has been marked as final. Show 4 replies
which is the first and which is the second rectangle? and what are you trying to do?
The draggedObject is the rectangle in the foreground which should be positioned in the center of the second rectangle (background). This should work for any position and angle of the second rectangle.
If it would be possible to position MC objects with the center as reference point for x and y coordinates it would be possible. So maybe someone has a solution for that.
Otherwise it seems to be quite hard to implement the correct mathematical formulas.
well, there are several ways to align objects on the stage.
1) construct the objects so that thier registration points are in the center of the object, then either can be aligned to the center 0,0 of the other, and rotated about that point.
2) if the objects registration point is in the upper left corner, use the Stage's width and height properties to align the obects to the center, by setting the _x position of the object by subtracting the width of the object from the width of the Stage and dividing the result by two. do this again each time you rotate an object, as the bounding box is changed to accomidate the entire bounds of the shape, after rotation occurs.
AS2: draggedObject._x += (Stage.width - draggedObject._width) / 2;
AS3: draggedObject.x += (stageWidth - draggedObject.width) / 2;
(I am uncertain if this is the correct method of calling of the AS3 'stageWidth' property here, as I'm new to AS3)
3) there are more ways to accomplish this, but this should be enough for now.
use the getBounds() method of the displayobject class to obtain a rectangle that you then use to center your rotated movieclip.